Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to make this play after the player dies too?

Asked by 9 years ago

I created this so the players could listen to music for a game I made but when the player dies.... The music stops. Probably due to the fact that the whole player was reset and the fact that the playergui area was reset so the music does not exist. Is there anyway to make this work when the player dies as well?

game.Players.PlayerAdded:connect(function(player)
wait(1)
local sound = Instance.new("Sound")
sound.SoundId = "http://www.roblox.com/asset/?id=300733201"
sound.Parent = player.PlayerGui
sound:Play()
sound.Looped = true
wait(70)
sound.Looped = false
local sound = Instance.new("Sound")
sound.SoundId = "http://www.roblox.com/asset/?id=170691997"
sound.Parent = player.PlayerGui
sound:Play()
sound.Looped = true
wait(50)
sound.Looped = false
local sound = Instance.new("Sound")
sound.SoundId = "http://www.roblox.com/asset/?id=262085924"
sound.Parent = player.PlayerGui
sound:Play()
sound.Looped = true
end)

1 answer

Log in to vote
1
Answered by 9 years ago

So all you have to do is use the died event. You are just a few lines away from your solution


game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(char) wait(1) local sound = Instance.new("Sound") sound.SoundId = "http://www.roblox.com/asset/?id=300733201" sound.Parent = player.PlayerGui sound:Play() sound.Looped = true wait(70) sound.Looped = false local sound = Instance.new("Sound") sound.SoundId = "http://www.roblox.com/asset/?id=170691997" sound.Parent = player.PlayerGui sound:Play() sound.Looped = true wait(50) sound.Looped = false local sound = Instance.new("Sound") sound.SoundId = "http://www.roblox.com/asset/?id=262085924" sound.Parent = player.PlayerGui sound:Play() sound.Looped = true end) end)

So what i did was add the character added event so it fires whenever a character is added to the player AKA when they re spawn.

Ad

Answer this question