Would repeat task.wait(1) until #game.Players:GetPlayers() >= 1 work?

I just had a simple question in mind (not using it anywhere)
would these three lines of code:

game:BindToClose(function()
   repeat task.wait(1) until #game.Players:GetPlayers() >= 1
end)

make servers last forever? (obviously not if servers are down but yk what I mean)

2 Likes

According to the Roblox API reference, the game will automatically shut down after waiting 30 seconds for any BindToClose functions to complete, regardless if they finished or not. So the answer to the question is no.

1 Like

No, but even if it did, it still wouldn’t even happen, as when all Players leave the Server, the Server will shutdown regardless as the statement is repating until the amount of players is less than or equal to one, because nobody is in the Server by the time the Server will shutdown, it would have stopped long before it.

The Servers will not wait for something to finish in your game, and never have, if this were to ever occur where a script would just forever yield a Server, that would be a vunerability, and would likely make roblox unplayable.

The Server just runs the game, and does complex calulations like physics. Scripts are like “extra work” that the Server needs to execute while up and running, when the Server shuts down, it will stop all the things that are going on in the Server including Scripts.

greater or equal is >=
not less or equal (<=)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.