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

Can loops pause the server?

Asked by 8 years ago

so let's say I was in an SB and I said this.


while true do Instance.new("Part", workspace) end

Even if everyone left, would the server be ongoing cause of the loop?

0
no, the server would instantly crash before loading LoganboyInCO 150 — 5y

2 answers

Log in to vote
4
Answered by 8 years ago

Synopsis

There are two possibilities that come into play when it comes to overloading a script with a loop, depending on what machine the script is running on (i.e, server or client).

In general, if you create an infinite loop, for example: while true do end without yielding, it's going to cause problems no matter what code is inside your loop (unless of course you have some kind of automatic garbage collector).

Client

Running an infinite loop from your PC (by using a local script), will cause only that application to crash (the ROBLOX game client). In some severe cases depending on your computer's processing power and what caused the crash, it can result in your entire PC crashing.

Server

Speaking for ROBLOX servers specifically however, is a different story. When an infinite loop on the server occurs, obviously, this is going to prioritize the loop over replicating information to all clients, causing everyone to technically be disconnected for a short while (until the server repairs itself). Because of that, this will only effect server-sided events, not local events (and I use the term event loosely). Now, most of the time crashes on the server, though should still be avoided, can take care of themselves.

A crash on the server usually is visible via the network receive display when you press shift+f5 in-game. You'll notice a tremendous drop, probably holding at 0.1 to 0 for a solid 5-10 seconds, then it will gradually start increasing again. It should look somewhat like this: https://gyazo.com/a4d537affb9752718f03cd2c183e64b3

Your question

So with that explanation out of the way, the short answer is no, the server would not keep going if there was a loop preventing the script from ending. The only thing that can keep a game from shutting down when no players are present, is the OnClose callback function. (See: https://scriptinghelpers.org/questions/28716/is-it-possible-to-keep-an-empty-server-active or http://wiki.roblox.com/index.php?title=API:Class/DataModel/OnClose)

Questions

And that's pretty much how that works. If you have any questions, just leave a comment or you can PM me if you want further detail.

0
As an extension to this, as you've answered it pretty well, on the server the script is forcibly yielded for some time after 10 seconds without any waiting in order to allow the server to catch up with other scripts. User#6546 35 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

This loop would crash the server. Everyone should crash, assuming it's ran by the Server and not a client. Also, if there was a wait, then everything would end like normal if all players left the server.

Answer this question