I have a for loop that moves objects to a table of positions and once that is finished i want to change each object to another position one by one. Is there a way I can delay the second bit until the first bit finished? Not using task.wait, task.delay, or task.defer … unless those would be a good idea to accomplish this. But I’m wondering if anyone has any other suggestions.
Maybe create an event that fires once all the positions from the first bit are done being set
what about the loops being in the same function?
Just use task.delay where the first parameter is the tween time for the parts in the first group
Maybe a bit of code would help. If you have a for loop moving things why couldn’t you just start the second part when that for loop has completed?
not tweening. just changing cframe. but in lua i suppose the loop will have to finish before the next loop can run? so maybe it doesn’t matter and/ or can just use task.wait
that’s what i’m doing essentially but i am looking for a way to “make sure” it’s finished before proceeding. just in case.
If you’re changing the cframe it’s the same idea, you should have a variable for how long it takes to complete so just use that
You’ll want to insert a delay between the two loops otherwise they’re just going to appear to happen instantly.
Make sure to mark this as solution too!
changing multiple cframe with loop.
so you mean a task.wait and i’m wondering about alternatives
Your loop should still have a timeout number which is the one you want to be using
Why do you want an alternative to task.wait()?
- You want to move the items from Position A to Position B
- You need some period of time for players to observe the items in position B.
- Then you want to move them to Position C
You need a task.wait() to handle step #2, otherwise it’ll just appear like A was moved to C.
so right now i’m just using a repeat wait until all the objects have been moved … then might put in a little wait after which i think will correspond with the camera tween
i’m exploring alternatives outside of task.wait just to see what other methods exist. but i haven’t found any so far
What do you mean “until all objects have been moved” – you’re not using a tween you said, you’re just setting the CFrame (:PivotTo() hopefully) directly aren’t you?
yeah. the objects i’m moving i’m putting in a table while they are where they are. so i’m checking to see if the objects in the table are all the objects. then i will probably do a task.wait() after that or in my repeat i’ll have it to also check a bool value to let know that it should continue. because i want a delay as well as checking when all the objects are where they are supposed to be.
It is hard to visualise without some code. I know how I would do this but that won’t help you because it probably wont look anything like your code. If you show the code I might be able to refactor it to make it do what you want.
Maybe try using a promise? Still not sure what the question really is tbh
this is just contemplating logic. not debugging or wanting to refactor existing code. but i’ve just ended up using a repeat loop until all objects are moved then a wait for delay until next loop starts.