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

Why do i get an error message "Game script timeout"?

Now I do understand the the error is a way for Roblox to stop long running scripts, but what I don't understand is what in my script is causing it and how can I fix it?

--The purpose of the script is to play music while a main menu is on.
--The Boolean in ReplicatedStorage is to let the script know if the MainMenu is on or off
--I could have used the Visible property itself but I thought it would be more cleaner to use that.
local Menu = script.MenuMusic 
local MenuBool = false
local Lobby = script.LobbyMusic
local LobbyBool = false

while true do
	if game.ReplicatedStorage.StartMenu == true and MenuBool == false then 
		Menu:Play()
		MenuBool = true
	elseif game.ReplicatedStorage.StartMenu == false and LobbyBool == false then
		Menu:Stop()
		Lobby:Play()
		LobbyBool = true
	end
end

1 comment

0

This while loop will prevent any other scripts from running as it never yield(waits) I am also not sure why you even need a loop?

1 answer

✓ Accepted answer

You should'nt use a while loop.

Use a .Changed event instead

game.ReplicatedStorage.StartMenu.Changed

Also on line 10 and 13 you should'nt do an if statement on a object, do it on the value instead

if game.ReplicatedStorage.StartMenu.Value == true then
   --Code
end

1 comment

0

i forgot to mention that using a while loop without using wait will make your game crash

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