while do loops
While do loops are used for endless loops, or even not endless loops.
while true do means that it will endlessly loop, however, it needs a wait() or the script will break
while wait() do doesn't form any error, since their are waits
"Why are there while do loops?"
while do loops are for something like, that this for example: kicking all of the players out of the game
while game.Players:FindFirstChild('Player') do
game.Players:FindFirstChild('Player'):Kick('Removed')
end
It will kick all of the players until there are none.
This is the same thing as while true do
Expect, that "true" can't change, so it's like keep on looping until true is false, which isn't happening.
While wait() do is basically it waits 0 seconds, then it loops again.
This is basically what it is.
"When should you use it"
If you want to make a loop start immediately, then use "while true do", but put a wait somewhere in the line, or else it will break
If you want it to, lets say wait a couple of seconds then it loops again, or make it not immediately start, use "while wait() do"
2 comments
Some people don't like using the number returned by wait() as the condition for their while loops, but it really doesn't matter.
By the way you can stop any sort of loop with break