@RedcommanderV2 Preferences can be wrong. Because you like something doesn't mean it's not wrong. Having preferences is not wrong, but preferring
while wait() do ... end
while true do ... end is.
while true do ... end is "better to use", as it is clearer. It clearly indicates that the loop will run infinitely, as its condition will always be
How does using
wait() as the loop's condition tell you that? The answer is it doesn't.
How does using
wait() as a loop's condition even make any sense? It doesn't either.
wait() as the condition for a
while loop is really a hack (not "hack" as in gaining unauthorized access to a system, but in the sense that it is a trick and an inelegant solution). The only reason it works is that the function returns a number corresponding the actual time Roblox waited before resuming the thread and, in Lua, in a condition context, any non-
false value is considered as
true (in programming terms, we say everything but
false is truthy).
It makes absolutely no sense to use that number as the loop's condition.
Furthermore, the chances of forgetting to add a call to
wait() and crashing studio are not smaller in any way if you follow good habits and write
wait() immediately when creating your
If forgetting to add a call to
wait() is really your concern, you could it at the top of your loop, just after the condition test:
while true do
-- do something...
Besides, studio has an autosave feature which makes sure to save everything every few seconds, as well as when launching a Play test. You shouldn't lose anything but your last few seconds of work.