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

My playlist playing songs in order makes a weird script error when all songs are done playing?

Asked by 4 years ago
spawn(function()
while wait() do
    if pops==true then
    wait(0.2)
         local  sound = pop[currentSong]
    print(sound)
    sound:Play()
    wait(0.2)
    if currentSong~=#pop then -- Shuffles through the song now
        currentSong = currentSong+1
    else -- Resets the playlist.
        currentSong = 1
print"detected pop" 
    end

    repeat wait() until sound.Playing==false 

end end end)

When all songs are done playing, it creates a huge error and plays songs in order every 0.2 seconds. It doesn't seem like it resetted the playlist. Any suggestions?

0
check if the last song in the playlist has ended, and then restart it by setting current song back to 1. killerbrenden 1537 — 4y
0
Yeah, the last song ended. I restarted the currentSong back to 1, but still doesn't work. TinfoilbotGamer 35 — 4y

2 answers

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
4 years ago
Edited 4 years ago

Why not use Math.Random() to choose a random song. or use tables?

Random song from playlist script

local songs = {"SongID","SongID","SongID","Just keep putting "" and a , for more songs"}
local songplaying = false

spawn(function()
while songplaying == false do
    wait()
    for i,v in pairs(songs) do
        local randomsong = songs[math.random(1,#songs)]
        wait()
        if not game.Workspace:FindFirstChild("GlobalSong") then
            local sound = Instance.new("Sound")
            sound.Name = "GlobalSong"
            sound.Parent = game.Workspace
        end

        songplaying = true

        game.Workspace.GlobalSong.SoundId = randomsong
        game.Workspace.GlobalSong:Play()
        game.Workspace.GlobalSong.Ended:Wait()
        songplaying = false
    end
end
end)

Play song in order

local songs = {"SongID","SongID","SongID","Just keep putting "" and a , for more songs"}
local songplaying = false

spawn(function()
    while songplaying == false do
        wait()
        for i = 1,#songs do
            wait()
            if not game.Workspace:FindFirstChild("GlobalSong") then
                local sound = Instance.new("Sound")
                sound.Name = "GlobalSong"
                sound.Parent = game.Workspace
            end

            songplaying = true

            game.Workspace.GlobalSong.SoundId = songs[i]
            game.Workspace.GlobalSong:Play()
            game.Workspace.GlobalSong.Ended:Wait()
            songplaying = false
        end
    end
end)
Ad
Log in to vote
0
Answered by 4 years ago

I've tried:

spawn(function()
while popplaying == false do
    wait()
if pops==true then
    for i,v in pairs(pop) do
        local randomsong = pop[math.random(1,#pop)]
        wait(0.1)
        popplaying = true
popsong.Value = randomsong
  script.Radio:FireServer("play", randomsong)
    randomsong.Ended:Wait()
        popplaying = false
    end 
end

end
end)

It works, but after all songs are over it no longer plays anymore...

0
It seems like you are using a localscript. Use a full serverscript for this. Lakodex 711 — 4y
0
That's ODDely strange. Are you sure this will fix it? TinfoilbotGamer 35 — 4y

Answer this question