I have local script that plays music, it works fine. But when the player dies the music resets and picks another song. I couldn’t find any online sources that would contribute into helping me fix, so I went to devforum.
local Music = script:WaitForChild('Music')
local Songs = Music:GetChildren()
local LastPlayed
local function PlayRandomSong()
local song = Songs[math.random(1,#Songs)]
if not song.Playing and song.Name ~= LastPlayed then
song:Play()
song.Ended:Wait()
LastPlayed=song.Name
PlayRandomSong()
elseif song.Name == LastPlayed then
PlayRandomSong()
end
end
PlayRandomSong()