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