Wait | wait | task.wait

General question, roblox has 3 different types of waits.

I understand the difference between task.wait and wait.

But why does Wait exist? is it the same as wait?
And why does Wait & wait return two vars/args?

image

Edit:
I couldn’t find the documentation for Wait | wait btw :+1:

Wait is just the old name for wait. It’s deprecated but it should be the exact same thing.

1 Like

You can use Wait to yield until a certain event occurs.

For example:

Humanoid.Died:Wait()

or

Remote.OnServerEvent:Wait()
1 Like

He was not talking about the RBXScriptSignal method :Wait(), but rather the global Wait function.

2 Likes

I understand the purpose of Wait.

So would Wait() be the same wait as a :Wait() :face_with_raised_eyebrow:

No.

:Wait() is a method for RBXScriptSignals (BindableEvents), which yields the current thread until :Fire() is called on the BindableEvent.

Wait() waits the specified amount of time, with throttling.

It’s important to note that both Wait() and wait() are deprecated, and have been superseded by task.wait().

1 Like

Dw I know that :sob: Just curious what Wait was specifically for and why it returns 2 sets of numbers
0.040968299999804 3720.69541567249

Do you want to know the difference between wait() and task.wait() or the difference between Wait() and wait()?

wait:

A deprecated usage of delays, superseded by task.wait.

Wait:

Typically used with events to pause its execution until an event is fired, for example:

Player.CharacterAdded:Wait()
print("Hello") -- prints Hello after player's character has been added.

task.wait:

The better wait, easiest way I can explain.

1 Like

I see, how about the second number Wait | wait returns?

Take this with a grain of salt (need fact checkers here):

I think it’s just the Roblox Studio engine. If you run it a few more times, you’ll see changes a lot.

1 Like

Wait and wait are the same. People saying Wait is used for signals are right but at the same time wrong in the context of this topic so please ignore them.

I believe the second argument for wait returns the CPU elapsed time.

1 Like

Yeah, it seems to increment by 1 second, maybe it correlates to how long studio has been open?
Merging the waits only creates one aswell
image

This seems to be the most likely answer, it makes sense as its incrementing in seconds

Yes, you should confirm it by restarting studio or your pc though, I’m not sure as the documentation is removed.

1 Like

Wait() and wait() returns a tuple; two numbers:

  • The first number is the exact time in seconds the wait took.
  • The second number is the distributed game time (just like workspace.DistributedGameTime) at the time of calling.
1 Like

Roblox’s Lua, like the regular Lua, used to be flatcase but, if I remember correctly, briefly attempted to switch their engine specific globals to Pascal. Later, they also changed all the API functions to Pascal, which is why you see so many alias’.

However, following the pattern of Engine Specific = Pascal, they did Wait(). But, simply speculating, they later decided these boiler-plate functions/globals, given they’re so frequent and necessary, should be flatcase (… and messily sometimes camelCase, and Pascal, ergo UserSettings()). This is probably because Lua globals like coroutine are, again, flatcase. Other examples are Workspace turned into workspace, Game turned into game, and finally, Wait() turned into wait(). It helps people mentally box together that lower case things are globals and pertain to fundamental interaction with the engine.

We use task.wait() now simply because its faster and doesn’t use the old LuaSettings.DefaultWaitTime and it doesn’t use the legacy scheduler, which was slower.

As for what it returns, the two variables are just how much time elapsed and the current game time.

1 Like