How do I make a sound in script local?

I want to make it so when the player dies it plays a custom death sound that will play when they die and keep going forever how long the sound is even after the players’ character has reloaded.

I have muted the current death sound, but don’t know how to make the sound I want to do what I said above.

What I have rn: (Not working)

	character.Humanoid.Died:Connect(function()			
		deathStat.Value = deathStat.Value + 1
		
		local SoundService = game:GetService("SoundService") --Ik this is a dumb place to put this 
		local newsound = workspace.Sounds.DeathSound:Clone()
		SoundService:PlayLocalSound(newsound) --This is getting an error 
		
		
		wait(0.5)
		player:LoadCharacter()
	end)

You didn’t give the sound to a parent.

Adding
newsound.Parent = character.HumanoidRootPart
and using
newsound:Play()
can work instead.

1 Like

Using this the sound does not keep playing after the players character has been respawned

Move all of that code over to a LocalScript. LocalScripts only work on the client and the only person who will hear the sound will be the requested client.

LocalScripts should be stored in StarterPlayerScripts or StarterCharacterScripts. OR if you’re feeling a bit rebellious, you can place it in StarterGUI or StarterPack.

local SS = game:GetService("SoundService")

local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()

	character.Humanoid.Died:Connect(function()			
		deathStat.Value = deathStat.Value + 1

		local deathSound = SS.Sounds.DeathSound -- Place all sounds in soundservice!
		deathSound:Play() 
		
		wait(0.5) -- you could also do deathSound.Completed:Connect(function()
		player:LoadCharacter()
	end)

Good Luck!

2 Likes

Saving it somewhere else as SoundService Can work then.

In this case, would I put it in starter character scripts?

No, Sound service. It should be in explorer.

I personally recommend StarterPlayerScripts since it doesn’t replicate it everytime the character spawns.

Local Script in StarterPlayerScripts
Sound Folder in SoundService

1 Like

Thought he meant the sound itself, my bad. :sweat:

You also don’t need to clone the sound in order to play it on the client, as long as you do it from a LocalScript.

1 Like

The died function is not working Im getting this error:
Humanoid is not a valid member of Model “Workspace.Its4Realzies”

Your humanoid is probably loading after the script. Try setting the humanoid before connecting the function.

local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

humanoid.Died:Connect(function()
    --Code
end)

1 Like

This is all the code. It only works, but only the first time I die. After that there is no errors, but no sound
local SoundService = game:GetService(“SoundService”)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)

humanoid.Died:Connect(function()
local deathSound = SoundService.DeathSound
deathSound:Play()
end)

edit: I moved it to character scripts and it works. Im dumb lol