You cannot “disconnect” a function, you can only disconnect an event. Therefore, if you would like to return early from a function, you would need to perform a check at every point you may want to exit. You could organize (what I’m assuming are) you animation (CoverUp, ClipOut, etc) into a table. Similar to the following:
local animSequence = {
{Anim = script.Parent.Handle.CoverUp, Duration = 0.45},
{Anim = script.Parent.Handle.ClipOut, Duration = 0.85},
{Anim = script.Parent.Handle.ClipIn, Duration = 0.5},
--And so on...
}
--Then include a for loop in your reload function like:
for i = 1, #animSequence do
local currentAnim = animSequence[i]
if module.Reloading then --I'm assuming this is the variable you would change to false if you want to cancel the animations
currentAnim.Anim:Play()
wait(currentAnim.Duration)
else
return --If you need do to some other cleanup outside the for loop but still in the reload function, you can use a break here
end
end
Are you using Animations or Tweens? I can help you with some smaller details but like @blokav said, we can’t just provide you with a complete script. It’s up to you to make sure the implementation is correct on your end.
Alright. I’m thinking there’s pretty much two options at this point.
You can continue the route you’re currently going with separate animations. I believe the code I gave you should be a good start but might not be working because of something else going on in the rest of your code.
This problem might be easier to tackle if you merge all the smaller animations into one single animation. That way, whenever you want to cancel the reloading, you can just simply call :Stop() on it.
which would work… but is bad code formatting because the “end” is actually closing the function, not acting as a returned value. Lua actually sees it as:
function go()
return
end
--This is correct code formatting and should be how you write it
-- because it will help you better understand how your scripts are
-- actually working, and maybe even eventually help you fix the
-- problem you posed in this topic.
the end in that case is closing the conditional. Single like conditionals are alright for small statements like that, but technically the correct formatting is: