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 script error “Game script timeout” when I run the game, and how do I fix it??

I made a local script to detect how many players are in the game, then put that on a text label. When I run it, it gives me “Game script timeout” on line 13. I do not understand. My script:

playerCount = game.Players.NumPlayers

if game.Players.NumPlayers >= 2 then
script.Parent.Text = game.Players.NumPlayers.." Players"
else
script.Parent.Text = game.Players.NumPlayers.." Player"
end

while true do
if game.Players.NumPlayers >= 2 then
script.Parent.Text = game.Players.NumPlayers.." Players"
else
script.Parent.Text = game.Players.NumPlayers.." Player"
end
end

7 comments

0

There

0

Sorry, there are indents in the actual code, IDK why not here.

0

because you have an infinite loop without a wait()

0

And NumPlayers isnt a valid property of the PlayersService

0

Yes it is

0

add a wait

0

you need to put a wait() at the end of the while true do

1 answer

✓ Accepted answer

there has to be a wait inside of any while true loop. Not doing so results in the timeout or roblox crashing. While true runs the code 30 times per second if not specified otherwise.

playerCount = game.Players.NumPlayers

if game.Players.NumPlayers >= 2 then
script.Parent.Text = game.Players.NumPlayers.." Players"
else
script.Parent.Text = game.Players.NumPlayers.." Player"

end

while true do
if game.Players.NumPlayers >= 2 then
script.Parent.Text = game.Players.NumPlayers.." Players"

else
script.Parent.Text = game.Players.NumPlayers.." Player"
end

wait(0.1)
end

1 comment

0

also read comments, a lot of other people said the same thing.

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