Why is wait() important?

As long as it doesn’t return nil or false, anything else will be considered true & it’s not directly printing true but actual values based on the wait, which way too many games take use of that it would be one of the last things Roblox want to change. But do they even have a reason to? I don’t think so.

1 Like

Even then, the code looks worse and isn’t anymore performant. You’ve saved one line if anything. The literal sounding of the code is also more confusing.

while true do
  wait(1)
end

“While true, wait one second”

Versus

while wait(1) do

end

“While waiting for one second, do what?”

This can and has confused people.

No way people are confusing it like that. No one is gonna make an entire loop just for a wait(), it’s obviously for all your code you want in the loop to run repeateadly.

Most of what I know is it just slows your code down, if you didn’t have wait() your code could slow down your game a lot depending on what the code is doing. Basically you should just try to put it into things you don’t want firing off every 0.001 second.

task.wait is basically a better version of wait because its more accurate.

That’s not the point, the point is the former looks cleaner while the latter just looks like you’re magically expecting wait to return something.

Anyway, lets stop debating.

1 Like

There might be that flaw, but wait() doesn’t really wait the exact time you told it to. Use task.wait() instead.

It is good to knowledge that problem though, but I still don’t see that as a reason to stop using task.wait(). Unless you run into that problem, which is rare

Wait() is important because you might need to make the script wait a few seconds.

if ur using a while loop, u need it for the script to not crash

Is there an announcement on this? Feels like a huge change.

Yes, it’s logged here

We will eventually mark the existing methods (spawn, delay, and wait) as deprecated in favor of their alternatives however they will continue to work as they do now for the foreseeable future and we have no plans to change this.

1 Like

So same functionality, just not recommended.

Honestly, I don’t think any ROBLOX game’s server will run for long enough to have the wait() affect anything crucial unless you just…don’t code properly. But I’ll start using task.wait() if it really makes that much of a difference.

1 Like

while wait is a bad idiom (search that up)

You can use that function to prevent script overload when you are using loops. It can also be really useful for timing things right or once everything is loaded in. Because problems can happen if the player isn’t loaded or something else.

I didn’t say they don’t wait the same time. I said that a while wait() do will wait BEFORE the code block executes where while true do executes the code block and then waits.

It’s just a question of placement.

This results in the same code, this is the same example you quoted in the original reply.

while true do
    task.wait()

    -- Code
end

while task.wait() do
    -- Code
end

Both of these would run the wait first.

What wouldn’t is this:

while true do
    -- Code

    task.wait()
end

This is literally what I said in my first message. I just didn’t provide a code example. I also probably could have explicitly said if you place the wait at the end.

?
You quite literally said that using while true do wait() --Code end would run code before waiting.

More specifically, you originally said “the second block would wait before running code”, the second block in the post you replied to, is this:

And you claimed the other block, (which is while true do wait() -- Code end) would run code first and then wait, which isn’t the case.

I guess I didn’t read his code fully or he edited to add the --code comment, because I didn’t see that before.