New Music starts playing every few seconds

Hiya! I am currently working on a playlist script. However, I have run into a problem. When I join the game the music starts, fine. But ever few seconds the song skips to the next one and I am not sure how to fix it.
Any help is appreciated

while true do
	wait(2)
	local CurrentlyPlaying = Music[math.random(1,#Music)]
	MusicPlayer.SoundId = "rbxassetid://"..CurrentlyPlaying
	wait(1)
	MusicPlayer:Play()
end
while true do
	wait(2)
	local CurrentlyPlaying = Music[math.random(1,#Music)]
	MusicPlayer.SoundId = "rbxassetid://"..CurrentlyPlaying
	wait(1)
	MusicPlayer:Play()
	MusicPlayer.Ended:Wait()
end

As czo has corrected, you haven’t told the script to wait for the song to finish, and every 2 seconds a new one will start otherwise.

Yes I noticed, thank you so much!

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