A new song plays before the song that currently plays ends

hello, i have a sound manager as a server script

local songs = script.Parent
local songstable = {}
local lastsong = nil

for i,v in pairs(songs:GetChildren()) do
    if v:IsA("Sound") then
        table.insert(songstable,v)
    end
end

local chosensong = songstable[math.random(1,#songstable)]

while true  do
	if raid == false then
		if playing == false then
			playing = true
			for a,c in pairs(songstable) do
				if raid == false then
					print("playing normal song (whiletrue loop normal)")
					repeat wait() chosensong = songstable[math.random(1,#songstable)] until chosensong ~= lastsong
					lastsong = chosensong
					chosensong:Play()
					chosensong.Ended:Wait()
					chosensong:Stop()
				end
			end
		end
	end
	wait(1)
end

it loops through a folder, then add its to the table, this is fine, however
before 10 secs, or more or less,another song starts playing despite having chosensong.Ended:Wait()
please help

I think you need a new playlist manager, so I made one for you

local songs = script.Parent
local currentsong

while true do
    local song
    repeat song = songs[math.random(1,#songs:GetChildren)] until song ~= currentsong
    song:Play()
    currentsong = song
    song.Ended:Wait()
end

hey it works!! thank you, rn im trying to implement it with the script cause i have important things there

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.