Sound changing depending on distance

Hello.
I was trying to make a script that if the player dies the sound will play and the sound will change depending on distance but i’ve ran to a problem. I wanted to change the volume on client sided with events but while i was ran to some error and i’ve quite fixed it but the volume didn’t changed while i was testing the script with my friend
I’m rushed right now so here’s both scripts
Server Sided:

local DeathEvent = game.ReplicatedStorage.DeathEvent

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local ScreamPart = Character:WaitForChild("Head")
		
		Character:WaitForChild("Humanoid").Died:Connect(function()
			local CloseFolder = script.Close:GetChildren()		
			local DistantFolder = script.Distant:GetChildren()
			local CloseNumber = math.random(1,#CloseFolder)
			local DistantNumber = math.random(1,#DistantFolder)

			local CloseSound = CloseFolder[CloseNumber]:Clone()
			local DistantSound = DistantFolder[DistantNumber]:Clone()

			CloseSound.Parent = ScreamPart
			DistantSound.Parent = ScreamPart
			DeathEvent:FireClient(Player, CloseSound, DistantSound, ScreamPart)
			CloseSound:Play()
			DistantSound:Play()
		end)
	end)
end)

Client Sided

local Event = game.ReplicatedStorage.DeathEvent
local SoundEvent = game.ReplicatedStorage.DeathSoundEvent
local Player = game.Players.LocalPlayer
local Character = Player.Character

Event.OnClientEvent:Connect(function(CloseSound, DistantSound, ScreamPart)
	local DisMagnitude = (Character:WaitForChild("HumanoidRootPart").Position - ScreamPart.Position).magnitude
	if DisMagnitude > 80 then
		DistantSound.Volume = 1
		CloseSound.Volume = 0
	else
		DistantSound.Volume = 0
		CloseSound.Volume = 1
	end
end)

If anyone can fix it thank you

1 Like

I forgot, but wasnt there a property about changing volume depending on the distance?

1 Like

RollOffDistance and RollOffMode right?

Like i mean that when the player hears the close sound the distant sound will mute

Like i don’t know how to explain it

I’m sorry but I don’t understand ?_?

I’ve found a fix for the script…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.