I want to make a playist that plays music on my game. I want to load the next song before it plays so there is no delay (I use music that are more than 2 min long)
The first song plays, but it just does not trigger the ending event...
The thingis that this works in studio, but not ingame, It does not even do the "End" print ingame from the last lines of the script.
I want to know what's breaking my thing and how could I fix it.
This is the script:
local List = { [1] = "218607791"; [2] = "218608165"; [3] = "218609229"; } local Music1 = Instance.new("Sound",game.Workspace) Music1.Name = "Music1" Music1.Volume = 0.1 local Music2 = Instance.new("Sound",game.Workspace) Music2.Name = "Music2" Music2.Volume = 0.1 local Current = Music2 -- I put this there so it changes to the Music1 local num = 1 function change() print("Changing") if Current == Music1 then Current = Music2 Music2:Play() Music1.SoundId = "rbxassetid://"..List[num] elseif Current == Music2 then Current = Music1 Music1:Play() Music2.SoundId = "rbxassetid://"..List[num] end if num == (#List) then num = 1 else num = num + 1 end end Music1.SoundId = "rbxassetid://"..List[1] change() Music1.Ended:connect(function() print("Ended") Music1:Stop() change() end) Music2.Ended:connect(function() print("Ended") Music2:Stop() change() end)
I'd say this is ROBLOX's fault. They're amateurs when it comes to messing with sounds. Try to make a loop and have it wait Music1's TimeLength and then play Music2, and wait Music2's TimeLength.
while wait() do Music1:Play() wait(Music1.TimeLength+1) --Give it a small delay print("Stopping Music1") Music1:Stop() change() wait(Music2.TimeLength+1) print("Stopping Music2") Music2:Stop() change() end
You may need to add a few delays so the game has some time to register the TimeLength for Music1 and Music2 for each time you change the SoundID