Should I use Wait() or Task.Wait()

So I looked around a bit.
And then I wondered,


Should I be using Wait() Or Task.Wait()?

  • What are the pros and cons?

I would say more but there isnt much more to say, so Im gonna leave it at that!

~FROYO~

6 Likes
12 Likes

While I don’t know the cons of Task.Wait(), it is 100% better. It is definitely more accurrate than the regular Wait(). If you’re still using Wait(), would reccommend to switch.

3 Likes

What are you using it for

While true do loops should be replaced with RunService.Heartbeat:Connect()

task.wait() is equivalent to RunService.Heartbeat:Wait()

2 Likes

Short answer, use task.wait instead of wait
Long answer:
There are no cons to using task.wait. The task library was added to supersede the normal functions such as spawn, delay, and wait. IIRC the issue with these functions was that they were throttled to 30Hz, which isn’t the case for the task library, meaning that if you just called task.wait without a duration parameter, it’d just resume on the next frame (like Runservice.Heartbeat:Wait())

6 Likes

Except that :Wait is rather expensive (or at least, much MORE than connecting) on Deferred Events; (even on Immediate mode) compared to just using Connect.

If you have a :Wait loop, it is basically every frame creating a new connection. That is not great.

task.wait() is better but it’s still not good.

If you’re trying to run something kinda of every frame, then use Heartbeat:Connect, not a while loop with task.wait(), that’s not what’s it’s supposed to be used for.

Edit: It’s actually not even the same because they return different elapsedTimes;

3 Likes

I set up a function to make the wait() command run through a stepped:wait() by whatever number, that seem to work better than wait() as far as lag messing up my script timing. Than I tired task.wait() and that was just the same as the funtion I created. Pretty sure that is what it is doing, so now I use task.wait().

There are an insane amount of posts regarding this already.

you couldn’t be more wrong their is pro’s and cons of every keyword in lua wait() being shorter then task.wait in and out of itself is a pro you still shouldn’t use wait() though

task.wait longer then wait is a con also

The amount of time it takes you to type a variable/function has no effect on its usefulness; that’s not a con

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.