I know that you need to have yielding functions such as wait() inside a while loop, otherwise it’ll crash, but why does this crash exactly? I’ve tried this in C++ and vanilla lua (lua 5.1 from the Ubuntu repository) and it doesn’t, so what’s different with Roblox?
Other Lua programs still crash. Some Lua executers prevent this from happening by stopping the program or artificially slowing down the program.
The reason it crashes on Roblox is that there is no code telling it to wait, causing it to technically run an infinite number of times. The CPU gets overloaded, and you crash. Roblox does have measures to not crash forever, hence the error message saying the script timed out.
Basically what happens is that each script runs under a coroutine.
Once each coroutine yields or dies (finishes), it continues and calls the next. When you use wait(), you also yield but tell it only to resume this coroutine once the time is up, so it effectively sleeps the amount you specify.
But when you create an infinite loop with no yield, it will not resume any other scripts or any other parts of the engine and the engine will be stuck on your script until either:
Your script ends/dies
Your script yields
The Luau VM determines that your script has hanged for too long and its coroutine is killed.