It's normally best to use regular scripts for things like this.
Instead of using a LocalScript in StarterGui, use a regular script in ServerScriptService.
To get the Player, use a PlayerAdded Event. Like this,
game.Players.PlayerAdded:connect(function(plr)
end)
The above gives us the LocalPlayer, in a way.
Now to play a sound Locally, simply place the sound inside of the player. First, let's make the sound using Instance.new().
game.Players.PlayerAdded:connect(function(plr)
local Sound = Instance.new("Sound",plr)
end)
Now all we have to do is set the volume of the sound, the id of the sound, and play the sound! Here's what your script would look like,
game.Players.PlayerAdded:connect(function(plr)
local Sound = Instance.new("Sound",plr)
Sound.SoundId = 0
Sound.Volume = 1
Sound:Play()
end)
This would be your script if you only wanted it to play once. However, if you want it to play whenever the player respawns, use a CharacterAdded Event. Like this,
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
local Sound = Instance.new("Sound",plr)
Sound.SoundId = 0
Sound.Volume = 1
Sound:Play()
end)
end)
That would make the sound play whenever the Character Respawns.
That's all.
Good Luck!
2 comments
You could use CharacterAdded, which will fire when the player spawns
If someone helped you, please accept their answer. This helps us a lot!