Yielding code inside a for loop

Hiya,

How can I yield code inside a for loop until the for loop is finished completely iterating through the table?

I was thinking of just counting up until I’ve reached the number of objects in the table and then running the code but I’m just curious if there’s a better or more efficient way to do it.

Thanks.

If you want a script to yield or pause until a specific event fires, use the RBXScriptSignal.Wait() function. if you want you could make a variable and when your code is done you can change the value and whatever script you want to yield will not run until the variables value has changed.

1 Like

create a bindable event and fire that when the for loop ends