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?
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)
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...