Sounds for respawn

Hi guys,I’m still new to scripting,I made a sound that I wanted to play when a player respawn.How can I do it ?

You add a playeradded event and inside it add a character added event and then you write

local sound = Instance.new("Sound")
sound.SoundId = TheSoundIdYouWantToPlay
sound.Parent = character
sound:Play()

And with that I think it’s done

Please tell me if it doesn’t work

2 Likes

If you want it to be each time the player gets a new character, you could either have a script in StarterCharacterScripts, that plays a sound (If you want it to come from the player’s character), or you could have a sound and then connect to the .CharacterAdded event and :Play() the sound when a character is added.

2 Likes

Why not just do sound:Play() rather than sound.Playing = true?
Edit, just curious, as :Play() sets the time position to whatever a script set it to last, or 0 if no script set the time position, and then sets .Playing = true.
So they do the same thing essentially, .Playing = true just bypasses the sound.TimePosition if it was set.

2 Likes

Everything inside server script service?And this is a local script or a normal script?Thank you

serverscriptservice, local

(30 chars, if you don’t know there is a certain amount of letters you need to make a post, in this case it was less so you just write 30 chars to make it over)

1 Like

LocalScripts don’t run in ServerScriptService. It should be put in StarterCharacterScripts.

If u want other people to hear the Respawn Sound, it should be a ServerScript hooked onto a CharacterAdded Event.

Oh yes, I forgot

30 chars

Script in ServerScriptService



game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
local sound = Instance.new("Sound")
sound.SoundId = "YourSoundID"
sound.Parent = character
sound:Play()
	end)
end)

Or use local script if you don’t want to make sound hearable to everyone

2 Likes

As @LukaDev_0 stated, local scripts don’t run in serverscriptservice, it has to be a normal script

1 Like

Yes I know, then put it in StarterCharacterScripts

2 Likes
local Player = game.Players.LocalPlayer


Player.CharacterAdded:Connect(function(character)
	local Sound = Instance.new("Sound")
	Sound.SoundId = "rbxassetid://134012322"
	Sound.Volume = 2
	game:GetService("SoundService"):PlayLocalSound(Sound)
	game:GetService("Debris"):AddItem(Sound, Sound.TimeLength)
end)

[Even More Options]

1 Like