Next song in loop won't play

I have tried just about everything to make this loop properly, but it won’t. None of the songs got deleted or anything, so I don’t know the problem. It plays the first correctly, but not the others. The loop seems to work so I think it’s something with the if statement. I’ve tried so many combinations for it, IsPlaying, IsPaused, Ended, Playing, TimeLength == 0, just about everything I could. Nothing worked. Thank you so much if you know the solution!

I’ve also tried no if statements and just waiting for the song to end,

songs = {
	"http://www.roblox.com/asset/?id=285768873 ",
	"http://www.roblox.com/asset/?id=6578243952  ",
	"http://www.roblox.com/asset/?id=172530048 ",
}

function tablelength(s)
	local count = 0
	for _ in pairs(s) do count += 1 end
	return count
end

length = tablelength(songs)
currentSong = 0

music = script.Sound

loop = true

while true do
	if music.IsPaused == true then
		currentSong += 1
		if currentSong > length then
			currentSong = 1
		end

		print("Now Playing - " .. tostring(songs[currentSong]))
		music.SoundId = tostring(songs[currentSong])
		music:Play()
	end
	wait(0.25)
end

why not make 3 sound object with 3 different music and use .Ended even

I just rewrote the script to something more efficient and compact. The script won’t loop unnecessarily whilst playing.

local Songs = {
	"http://www.roblox.com/asset/?id=285768873 ",
	"http://www.roblox.com/asset/?id=6578243952  ",
	"http://www.roblox.com/asset/?id=172530048 ",
}

local Music = script.Sound

while true do
	currentSong += 1
	if currentSong > #Songs then
		currentSong = 1
	end

	print("Now Playing - " .. tostring(Songs[currentSong]))
	Music.SoundId = tostring(Songs[currentSong])
	Music:Play()	
	Music.Ended:Wait()
end
1 Like

Thank you so much! Sorry, I’m still pretty new to lua.

It’s supposed to automatically adapt to how many IDs you put.