Stopping the last fired event after the new event fired

I will try my best to explain what I am asking.

--a loop here

so now the question is, how do I entirely stop whatever is running (in this case its a loop) in the last event after a new one is fired?

The easiest way is probably to just have a single loop outside of the event, and have the event just change some variables that the loop uses.

Otherwise you can have each loop given an “ID” and change that when an event triggers. This way might have issues where the first loop still is finishing up when the second loop starts, though, if you’re not careful. But the general idea is like

local counter = 0

  counter = counter + 1 -- stops other loops
  local myCounter = counter
  while counter == myCounter do
    print("running loop", myCounter)
  print("loop", myCounter, "interrupted")
1 Like

Thanks for the idea, this will greatly help aid me in future scripting :smile: