Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What's the real difference between while true do and while wait() do?

I'll always see things like use while true do or use while wait() do. I'm really confused on which I should be using. What is the real difference?

7 comments

0

while true do is better

0

that will explain everything

0

(Sorry for my bad en.)When you use "while true do" the script repeating, when the script inside of it ends. So if you use "while wait() do", when script inside of it ends, next repeat starting after any seconds(while wait(3) do - repeating after 3 secs)

0

while wait() do should not be used.

0

ever.

0

Yeah really read the article Phlegethon5778 posted. You also shouldn't use wait() as your condition because it's a hack. It abuses the fact that wait returns a number corresponding to the time that the thread was yielded for.

1 answer

while true do will keep looping while a value you set is true.

For example:

local CatsAreCute = true
while CatsAreCute do
print("Cats are cute.")
end

But if you change the value to false, it won't work because it is not true anymore. You can also do a while false do.

But in a while wait() do it will keep looping endlessly while waiting literally no seconds, it will keep on instantaniously, but with some small intervals to avoid crashing and loss of data.

This discussion is preserved as it was. New answers, comments, and votes are closed.