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)
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)
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)
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