exploring ways to not start a function until one finishes
yeah, promises are used for exactly that
function1()
function2()
function2 dutifully waits on function1().
Um excuse me sir but function2() would run immediately after function1() and if function1() doesnât yield on the tween it will mess up
iâve only used promises while using remote functions in knit. would it make sense to use a promise in this situation? where i want to make sure iâve done alls i need to do for each player (my for loop is finished) before moving on⌠right now i am using a repeat wait until
what if there is no tween on function one?
If youâre using a for loop it will only continue once it has completed everything inside, you can guarantee that nothing will overlap or happen prematurely with
for _, player in players do
-- ...
end
Alternatively if youâre doing something that requires some time, you could count the number of players, make a new variable with the value of 0 and increment it by 1 each time the action has completed for each player, and use task.wait until both numbers are the same
local playerCount = #players
local completed = 0
for _, player in players do
task.spawn(function()
-- ...
completed += 1
end)
end
repeat
task.wait()
until completed == playerCount
Either this or using events will be the best approach