I'm trying to make a list of music which can be interacted by other users, but right now I'm stuck in a place where I don't know how I can make the code check if the 'Serverdefaultlist' to loop back to the first songs when the queue ends.
Serverdefaultlist = {1887115023, 4418905745, 497810777, 1477278823, 1572404379, 4924940868, 4689425151} Userinputlist = {} mainMusicList = {Userinputlist, Serverdefaultlist} local songcount = 1 local sound = Serverdefaultlist local music = script.Parent while true do wait() music.SoundId = "rbxassetid://"..sound[songcount] music:Play() music.Ended: wait() if --this is where the code stops since Im stuck and idk what to do end
Try using a for loop. It'll allow you to go on to the next song and loop back to the beginning when you reach the end of the queue. I explained how it worked in my comments.
Serverdefaultlist = {1887115023, 4418905745, 497810777, 1477278823, 1572404379, 4924940868, 4689425151} Userinputlist = {} mainMusicList = {Userinputlist, Serverdefaultlist} local sound = Serverdefaultlist local music = script.Parent while true do for i = 1, #sound do wait() music.SoundId = "rbxassetid://"..sound[i] -- because i increases each time this loops, it will play the next song id in the table. music:Play() music.Ended: wait() if i >= #sound then -- let's say you're on the last song. i would be equal to 7 then. There are 7 objects in the table. This if statement would be true and then on the next line, we make i equal to 1 again so it plays the first song id in the table the next time it loops. i = 1 end end end
I see it's a playlist. So after while true do
Do
wait()
music.SoundId = "rbxassetid://"..sound[songcount]
music:Play()
music.Ended: wait()
Repeat the same thing till you have all the songs.
I will explain it. It's a loop that starts with the first wait() and the rest of the script, when the music is ended it goes to the next wait() and keeps going. And what happens at the end? It looks for the next wait() that is at the start and that's how you make a playlist! Hope this helps you :)