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

Why does my script error “Game script timeout” when I run the game, and how do I fix it??

Asked by 4 years ago
Edited 4 years ago

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
0
There NickIsANuke 217 — 4y
0
Sorry, there are indents in the actual code, IDK why not here. NickIsANuke 217 — 4y
0
because you have an infinite loop without a wait() theking48989987 2147 — 4y
0
And NumPlayers isnt a valid property of the PlayersService theking48989987 2147 — 4y
View all comments (3 more)
0
Yes it is NickIsANuke 217 — 4y
0
add a wait EmbeddedHorror 299 — 4y
0
you need to put a wait() at the end of the while true do SamZeKat 28 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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
0
also read comments, a lot of other people said the same thing. EmbeddedHorror 299 — 4y
Ad

Answer this question