Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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
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? User#5423 17 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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
0
i forgot to mention that using a while loop without using wait will make your game crash xJathur95x 129 — 5y
Ad

Answer this question