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

Why does my music script stop and in output it says "Game script timeout"?

At the first line it just say "Game script timeout" in output.

if not sound.IsPlaying then
	setSong()
	sound:Play()
end

I hope one of you guys can help me. - Toby

3 comments

0

(There are more in it, for example the "setSong()" is a function in the script. It's just the first line it's stops at.)

0

Can you explain clearly please

0

Look down, I posted the full script.

2 answers

✓ Accepted answer

This is because while loops run very fast. In fact, all loops run at high speeds, and for that require a cooldown to prevent them from overloading the runtime. To solve your issue, write wait() next to do.

Here is the full script:

local sound = game.Workspace.Sound

local songs = {2870416424, 1837466718, 1838103223}

local Song = 1

sound.Looped = false

while true do
	function setSong()
		
		local song = songs[Song]
		
		print(Song)
		
		Song = Song + 1
		
		sound.SoundId = "rbxassetid://"..song
		
		print(Song)
		
		if Song == #songs then
			Song = 1
		end
		
	end
	
	if not sound.IsPlaying then -- Stops at this line.
		setSong()
		
		sound:Play()
	end
end

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