Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

2 comments

0

check if the last song in the playlist has ended, and then restart it by setting current song back to 1.

0

Yeah, the last song ended. I restarted the currentSong back to 1, but still doesn't work.

2 answers

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

2 comments

0

It seems like you are using a localscript. Use a full serverscript for this.

0

That's ODDely strange. Are you sure this will fix it?

This discussion is preserved as it was. New answers, comments, and votes are closed.