Deeper Look into Wait()

Hi!
I’m not looking reignite the "while true do wait() vs while wait() do war", but I’m interested a couple of the things people have mentioned.

  1. Is there a bug that causes wait() to return false? Some have said if wait() goes too fast it will return 0 and cause while wait() loops to break, however:
    print(0 and true) → true
    [The loop will continue, regardless of having 0 returned to it]

  2. Can wait() experience anomalies where it may never return?

  3. Can wait() be delayed to the point it will error? Using different methods, I’ve been unable to cause wait() to timeout.

  4. Do any of the above questions apply to other wait methods, such as: task.wait(), [event]:Wait()?

ps. If you have a comment not directly related to the above Qs, please Direct Message me.

Thanks! ^ ^

Who said that?? wait() will always return 0.03, that is it’s default value, it is either that or 0.3.
Though, I highly recommend using task.wait() it runs on 60fps unlike wait() which runs on 30fps. Plus it’s future-proof meaning wait() might get deprecated.

Not everyone is 100% correct, and some were under the impression wait() if going too fast will return a non-truthful argument.

wait() never goes too fast or slow, it’s all on server performance, it’s purpose is to yield. It’s not .HeartBeat()

Wait() can cause lag issues. If you’ve ever seen a player moving then pause and appear somewhere else 3 seconds later you’ve seen it.
I’d think it would be more a timeout for the wait issue.
@weakroblox35 I’ve seen many posts that talk about wait() taking more than .03 seconds.

wait() just yields code, I don’t think it would return as false or at all.

task.wait() is a newer version of wait(),

Another Method of Yielding code, but instead, it waits until fired or Changed

Do you want to do it in a kind of loop? to load ?

Yeah wait() seems to return 0.04264230000262614 17288.045851547155 while task.wait() returns 0.01158220000070287
image

2 Likes

Please DM me if you have a response not in direct response to the questions. I know not to use wait, however i’m interested in any rare bugs that might be present.

Yes, wait it takes a little longer to perform tasks, taskWait helps to hold tasks before performing properties.

repeat task.wait(0.01) until --code

wait() will not return any bugs, it will always return 0.04264230000262614 17288.045851547155 as shown above, if you want a future-proof and faster “loop” you can use task.wait().
plus wait() will never return booleans only numbers.

Exactly, there are however a lot of people who use the argument of wait() possibly returing false as a reason not to use while wait() do.
I’ve experience pretty bad engine bugs before, and wouldn’t be surprised if wait() also has some.

Who told you it will return false? Have you seen it in the official documents? I have never seen a function that is meant for numbers return a boolean evevr.

while true do
   wait()
   print("lol")
end
-- is the same as
while wait() do
   print("lol")
end

Officially there should be no reason to return false. I’m saying that some in the community believe wait() can rarely return false [this could be due to a bug], and I’m interested in if there is one.

No

No, but it can last longer than the number you give it if it’s being throttled

If “it” is wait, then no

No, but you should probably use task.wait() instead (I forget if we deprecated wait() or not, but I can’t think of any good reason you’d want to use it)

6 Likes

The bug doesn’t even exist in original lua, why would it exist in luau?

You can use wait() if you want a slower loop. : ) (Don’t wanna write down task.wait(0.04264230000262614))

You use while true do to determine if the condition is true, while wait() do will do the same thing but (this is a IF according to many posts, which doesn’t mean its true) if it returns false, it will break, from what I see is just IFs, not it does, or it will, its mainly just them saying potentially if roblox made it return false.

However just so you know, it isnt true

task.wait(0.03) will probably get you what you want, I don’t know if I would want to be beholden to throttling I don’t control to such a degree as a developer :woman_shrugging:

I don’t think it has anything to do with any potential bug/breakage (there’s no chance we’d ever make wait() return a falsy value especially given the prevalence of while wait() do), but simply that while wait() do looks kinda weird. I don’t like abusing truthiness like that, but it will never break.

2 Likes