What does repeat wait() until do?

Im trying to learn more about repeat until, and I saw someone do

repeat wait() until

what does that do?

3 Likes

Uh, i mean that does nothing… you first need to make something to happen, and then type that wait() that wait needs to be at the end of that loop, and what it does is that to make the action again, it needs to wait that between actions

Example:

local Apples = 0

repeat Apples += 1 wait(2) until Apples == 10

Every 2 seconds, the loop will add an apple to the apples variable until the variable hits 10

3 Likes
repeat
   -- code
until -- until this is true

If you have a script like:

repeat
   -- code
until false

It will repeat the code indefinitely. If it’s true, it will only run it once.

1 Like

It waits until a certain condition is met.

For example:

repeat wait() until activated = true end
1 Like

OP asked specifically for what repeat wait() until does.

3 Likes

oh yep, i forgot that… your post means the thing that he wants i think

repeat wait() until basically just put the script on hold until whatever is after until is equal to true.

That’s probably not the best way of explaining it to I’ll elaborate more with an example

Say, you wanted to wait for the player in a script, you would do:
repeat wait() until game.Players.LocalPlayer

Alternatively, if you wanted wait for a specific folder in the player, you would do:
repeat wait() until game.Players.LocalPlayer:FindFirstChild("SomeFolder")

repeat ... until is a loop that will keep running until met with a condition.
In this case, it’d keep waiting until something happened.

Now, the ‘wait’ [better to use task.wait] is just a delay that in this case, will keep waiting until your condition happened.

2 Likes

@Antonon_07 @Valkyrop I appreciate your efforts, but you’re just repeating what I’ve already said, just longer. Please read the replies to make sure you’re actually adding something useful.

It’s basically the same as if you were to do:

while wait(timeout)  do
    — Code
    if condition then break end
end 

At least functionality wise, not sure about performance or stuff like that

3 Likes

You can’t tell people not to share their opinions/replies on a topic. You never know if someone may use one of them.

That’s not what I’m saying. I’m telling you that you’re just repeating what I already said.

No, it’s not. repeat runs and then checks, while checks and then runs. This means that repeat will run at least once:

repeat
    print("repeat: Looped") --> prints
until true --> checks

while false do --> checks
    print("while: Looped") --> doesn't print
end
3 Likes

The solution OP has marked is wrong, as @VegetationBush has stated. Please mark the correct reply as the solution, as it would confuse future readers otherwise.

I have edited my response to make it basically the same function

Please read @VegetationBush’s response. Repeat and while don’t do the dame thing.

I have read it, however by moving the check with break line to the bottom of the code will guarantee that the loop will run at least once.

If you have a while wait() do loop and then add a check at the bottom it will work like repeat wait() until

1 Like

Ah, I see now. It didn’t update to the edited version before I reloaded it.
:joy:

1 Like

Yeah well I didn’t change anything from the edit when the day the topic was made other than adding that code comment so it’s more clear where the code would go so if would run at least once.

Your explanation maybe better however offering visuals of something that OP already knows can help them understand more.