Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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?

0
while true do is better User#21908 42 — 5y
0
that will explain everything User#21908 42 — 5y
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) HaveASip 494 — 5y
View all comments (3 more)
0
while wait() do should not be used. User#21908 42 — 5y
0
ever. User#21908 42 — 5y
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. User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Ad

Answer this question