Wait until something is true

Hey i want to wait until a specific thing happens or is true
I tried many scripts but none worked. if statement does not “Wait”.

i tried:

repeat
 Wait()
until -- what needs to happen
-- what happens after

and

while wait(1) do
-- an if statement

and many other scripts but none worked. I want to wait until something happens

2 Likes

what are you trying to do?
I can help if you don’t explan.

1 Like

That should work unless the value was set by the opposite side (if the value was set by the client it won’t be read by the server visa versa). In that case you would need to use events to send information between server and client.

1 Like

Well I found one issue,

repeat
 Wait()
until -- what needs to happen
-- what happens after

The script above wouldn’t work because “Wait” is capitalized. Maybe that is your issue. Try changing it to “wait” and see if it works.

Also, they should be using task.wait() instead of wait().

repeat task.wait() until true --replace 'true' with value
while not true do task.wait() end

However, generally waiting until something is true is not a good idea. Events such as PropertyChanged should be used instead where possible.

That is exactly how you would achieve that in a loop (without the use of external instances), otherwise you’ll need to make use of RemoteEvent, RemoteFunction, BindableEvent, BindableFunction and ValueBase instances to accomplish this.

There is no difference. task.wait waits without throttling and the other with

task.wait() is more accurate and wait() is depreciated. Use task.wait() for all future projects.

Wait() isn’t really deprecated, but Roblox does suggest that task.wait() should be used instead.

The definition of depreciated means that it is no longer supported. It only exists to keep older code from breaking. Roblox has declared wait() as depreciated. I can’t even find it listed anymore.

While wait() may be deprecated, it’s mostly pedantics. task.wait() is significantly faster, so it’s going to be more accurate on when an event happens. task.wait() is better to use unless you really need that naturally longer wait time for something to happen. (I’ve had times where I need to use wait() over task.wait() because it’s just that smidge longer, without being too long)

Dantheman is right though, nearly always you’d be far better off waiting for events to run functions (PropertyChanged, ChildAdded, so on and so forth) - From my personal experience, unless you’re trying to track a billion things happening at once in mass, you’re better off using those.

1 Like

The wait being longer isn’t a feature lmao

Depending on what it is you’re waiting for (If it’s an event from anything), you could just use :Wait().

For example, if you are waiting for the player’s character to load in, you could do:

localPlayer.CharacterAdded:Wait()


The [deprecated] tag is missing
roblox wait deprecated tag not there

number , number wait ( number seconds = 0.03 )

I’m not sure where you see those tags, but Roblox has stated that they either are or will be depreciated.

Supposing you have a BoolValue object (name: myBool) and you want to wait it to be set to True:

while not myBool.Value do wait() end

Make sure that myBool will be set to true in anyway, or it will stuck in this loop.

1 Like