Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I change the sound that plays when a player dies?

Asked by 4 years ago
local death = script.Parent:WaitForChild("HumanoidRootPart"):WaitForChild("Died")
death.SoundId = workspace:WaitForChild("Ding Ding!").SoundId

This is a LocalScript in StarterCharacterScripts. It works in studio but not in team test.

1 answer

Log in to vote
2
Answered by
Nanomatics 1160 Moderation Voter
4 years ago

First of all, make sure you commit scripts that you edited under the "Drafts" tab which can be found under "View" in the top ribbon when in team create.

Second of all, since the sound is under the character model, which is in workspace. You will need to use a Serverscript not a local one, because that sound plays on the server side, meaning everyone can hear that sound, not just the player that died.

That being said, we can use the PlayerAdded event of the "Players" service, and then the CharacterAdded event of the player object in order to change the SoundId of the death sound everytime the player respawns.

So it's going to look something like this:

Serverscript - Place it in "ServerScriptService"

game.Players.PlayerAdded:Connect(function(Player) -- everytime a player joins do what's below
    Player.CharacterAdded:Connect(function(Character) -- if player respawns do what's below
        local diedSound = Character:WaitForChild("HumanoidRootPart"):WaitForChild("Died")
        diedSound.SoundId = workspace:WaitForChild("Ding Ding!").SoundId
    end)
end)

Hope I helped! If you have any questions please let me know.

Ad

Answer this question