I have a loop that spawns a new function each time it's ran, but I want to know if there's an easy way I can revoke that spawn() if it's not completed by the time the loop is ran again?
Example:
while wait(5) do
print("yes")
spawn(function()
for i=1, 10 do
wait(math.random(0,1))
print(i)
end
end)
--The for i=1,10 has a 50% chance of completing itself before the while loop runs again, but I want to be able to cancel it so I don't have 2 spawn()s running over each other at once.
end

5 comments
wait() should NOT be your condition in while loops.
Why not?
https://gyazo.com/0d455984fe8bcbca85c035d6e55d9cb2
That doesn't prove anything. I agree with Link saying it makes more sense to use
trueas the condition in a while loop. I do not agree with him stating that this is what is RIGHT, and moreover, usingwaitin the condition is WRONG. This is his preference, and truthfully both ways are fine. It doesn't affect the program in any way other than the yield initiating the loop*.I agree with goulstem, from what I've read it basically states that it is NOT okay, but it doesn't actually tell you why other than it being a "hack" (which it gives no evidence of this either)