I'm trying to have this play a different songs 3 times after the first one ends... What am I doing wrong? (This is only part of the script)
local randIndex = math.random(1, #songs.titles); local title = songs.titles[randIndex]; local id = songs.ids[randIndex]; print("Trying to play") music:Stop() wait(0.01) music.SoundId =("http://www.roblox.com/asset/?id="..id) print("Now playing: "..title) music:Play() wait(0.01) for i=1,3 do local randIndex = math.random(1, #songs.titles); local title = songs.titles[randIndex]; local id = songs.ids[randIndex]; print("Trying to play") music:Stop() wait(0.01) music.SoundId =("http://www.roblox.com/asset/?id="..id) print("Now playing: "..title) music:Play() wait(0.01) repeat wait() until music.Ended:connect() end print("Lol")
Your code assumes the Ended event returns a boolean. By definition, events don't return values. It would be best for you to set a flag when the song ends:
local songIsEnded = false;
You'd then set that flag to true when the "Ended" event is triggered:
music.Ended:connect(function() songIsEnded = true; end)
Then in your loop you'd have:
repeat wait() until songIsEnded -- Reset the flag songIsEnded = false;
Hmmm.... This isn't the best thing but instead of using repeat wait() until music.Ended:connect() try:
t=0 repeat wait(1) t=t+1 until t>music.TimeLength