What is the function of While true do
While true do?
2 answers
Here's a fairly official looking definition of a while loop in Lua:
http://www.lua.org/pil/4.3.2.html
A while x do loop is used to do exactly that, loop! But x doesn't have to be "true" it can be any boolean expression (i.e. something that is either true or false)
So in the example you gave @hassancan of the while true do loop, because true is always, well, true, the loop will just keep going for ever! (Or until the script itself stops, such as by setting the Disabled property of the script)
Also bear in mind that if you do use an infinite while true do loop you must use a wait() in the body (contents) of the loop or else it will consume all of the available processing power for that server/player and crash.
while true do
wait()
--Do something over and over here!
end
I hope that answers your question!
It loops a script.
2 comments
It loops the scope of the while loop, not the script itself.
thank you
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
It's also possible to do "while wait() do / end" to condense the code slightly.