Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How am I able to make the coding check if the list ended and loop back to the beginning?

Asked by
LIRI1 7
4 years ago

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
0
Can you specify what you want checked in the 'Serverdefaultlist'? VitroxVox 884 — 4y
0
In the 'Serverdefaultlist' is all of the songs that are already chosen to be in the loop queue, and every time the last song ends, I want it to go back to the first song. LIRI1 7 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
Works perfectly! Thank you very very much for your time! :D LIRI1 7 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Answer this question