Music stops playing when the player dies

I am trying to make it so when a player dies the music continues to play, right now, when a player dies the music stops. The system I have set up is I have one event that fires whenever someone touches a part, and then is checking if certain values are set to true, and if they are, it plays a sound that is in StarterGui. Is there a way that it can pause the sound on death and not stop it? Because I want the TimePosition to stay the same. Is there other ways I can go about this? If you could point me in the right direction it would be very appreciated. I looked on the dev hub and the dev forums and could not find an answer.

Thank you!

  • Muffin
1 Like

When a players character dies, their Backpack & PlayerGui is deleted along with them, because those items are given when a character is added. Therefore, the sound will be deleted & stopped too when the character dies.

To have the sound keep playing after death, you can put the sound inside the actual player (game.Players.Playername). If you want to pause it when they die and resume when they respawn, its as simple as hooking up a listener for the characters death, pausing, and then resuming when the character is re-added.

Hope this helps!

8 Likes

you can see when a player respawns using this code:

game.PlayerAdded:Connect(function(plr)
local Respawns = -1
plr.CharacterAdded:Connect(function(char)
        Respawns = Respawns + 1
        if Respawns == 1 then
               -- Code
        end
end)

One small change Iā€™d make is

if Respawns >= 1 then

as opposed to

if Respawns == 1 then

just because people can die more than once!

1 Like

sorry! It was a mistake becouse i write it fast.

1 Like