Song no replace on the end

hi so i made a script that have to replace the song if the song ended but that cant change/replace the music when the music ended sombody can tell me why? and how can i actually fix that…
here is the script:

local Songs = {
	Song1 = "rbxassetid://609760145";
	Song2 = "rbxassetid://4508163804";
	Song3 = "rbxassetid://301217890";
	Song4 = "rbxassetid://1102170531";
	Song5 = "rbxassetid://1102130218";
	Song6 = "rbxassetid://3417133618";
	Song7 = "rbxassetid://290176752";
	Song8 = "rbxassetid://1851637813";
	Song9 = "rbxassetid://1841988384";
	Song10 = "rbxassetid://330094723";
	Song11 = "rbxassetid://292146823";
	Song12 = "rbxassetid://1347235854";
	Song13 = "rbxassetid://363196126";
	Song14 = "rbxassetid://294096668";
	Song15 = "rbxassetid://446510533";
	Song16 = "rbxassetid://2676688936";
	Song17 = "rbxassetid://182448496";
	Song18 = "rbxassetid://1323196760";
	Song19 = "rbxassetid://657360299";
}

while wait() do
	if script.Parent.TimeLength == 0 or script.Parent.TimeLength <= 1 then
		script.Parent.SoundId = Songs["Song"..math.random(1, 19)]
	end
end
2 Likes

You should use this: Sound | Documentation - Roblox Creator Hub

1 Like

Also just use an array…? Try something like this instead.

while true do
    sound = sounds[math.random(#sounds)]
    audio.SoundId = sound
    audio:Play()
    audio.Ended:Wait()
end
1 Like

sorry but that no works… @Wunder_Wulfe

sorry but that no works… @vwize

works for me so im not sure whats wrong

just look at down… (on studio is show errors)

I told you to use an array instead of that dictionary. Also, its not there for you to just copy and paste because of course you still need to create the audio source audio and use the right variables appropriate to your code (i.e. Songs)

1 Like

i did that already is what i used with your one… maybe let me try again to make sure
image

is it playing? You also have 19 sounds, not 9
Try this event (Sound.Ended) instead of Stopped as well

sound.Stopped:Connect(function()
	sound.SoundId = Songs[math.random(1, #Songs)]
	sound:Play()
end)

If this doesn’t work try using the .Ended

1 Like

i tried sound.ended and the song playing but the problem is that actually when the sound ended is just no playing another song.

while true do
	sound = sounds["Song"..math.random(1,19)]
    local audio = script.Parent
	audio.SoundId = sound
    audio:Play()
    audio.Ended:Wait()
end

Try this

1 Like

thanks is works! :smiley: @SansariGames

just for the record that script is exactly what i had written except audio was assigned to so it was something you had written and i guess the dictionary thing because still not using an array…?

1 Like