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 with a while true loop timeout?

Error game script timeout. There is a few second pause before I get this error when I start the game. game.Players.PlayerAdded:Connect(function(player)

while true do

if player:WaitForChild("leaderstats").AutoClickers.Value >= 1 then

player.leaderstats.Clicks.Value = player.leaderstats.Clicks.Value + (1*player.leaderstats.AutoClickers.Value)

wait(1)

end

end

end)

1 comment

1

Use a code block, this is an eyesore to look at.

1 answer

✓ Accepted answer

Try this: Message me if it doesn't work

game.Players.PlayerAdded:Connect(function(player)
ls = player:WaitForChild("leaderstats")
  while true do
        if ls.AutoClickers.Value >= 1 then
	    ls.Clicks.Value = ls.Clicks.Value + ls.AutoClickers.Value
	end
wait(1)
  end
end)

I do not recommend using while true do though. There are many other alternatives.

As for why it freezes during the startup, thats because you had the wait(1) inside of the if statement. So until the leaderstats actually existed, then it would the block of code would be running at a ridiculous rate.

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