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")

4 comments
OOh, couldn't you repeat wait() until music.Ended:connect(function() return true end) ?
@BobserLuck I assume that would probably work. The only issue with that approach is that would add a Ended event listener to music every single frame, which is very, very inefficient. This is assuming Rbx.Lua isn't smart enough to not instantiate multiple event listeners that do the exact same thing, but I doubt it is.
Good point. You could have a longer wait but having one event listener is enough. I was just wondering if it could work.
The wait time would be miniscule. We're talking nanoseconds.