Cancelling an if statement from outside?

So while working on an FPS system, I’ve run across the problem of making auto-reload cancel when you shoot. Currently when you click it does this:

(pseudocode + unneeded fluff removed)

function MouseDown()
--shoot
--I want this function to cancel reloading
end

function MouseUp()
--cancel shooting
     if not reloading and not shooting then
          reloading = true
          wait(ReloadTime)
          --Now I know some people will say to check if you're shooting here,
          --but that will only check if the mouse is down after the yield
          --meaning that shooting mid-reload will still allow you to finish reloading
          Ammo = MaxAmmo
          reloading = false
     end
end

I’m stumped and tired. If you need further clarification please ask. I’ve spent around 5 hours on this one simple concept.

Things I've Tried
  1. Disconnecting the function (oh wait i cant use the function again after Disconnecting)
  2. That stuff I commented
  3. using a function inside the if statement to return
  4. making a hacky function that would cancel when another function is called (see 1)
  5. making a loop that would only run once every time the function is called
  6. a million other things
  7. asking it nicely

ask questions if needed

Store the time they last shot and if tick()-lastShotTick() < ReloadTime, they can’t have reloaded.

1 Like