How to tell when animation has stopped (picking between a marker or just AnimationTrack.Stopped)

I need to see if an animation has the “HitStop” marker that indicates when to turn off the hitbox. If it doesn’t, I need to just turn off the hitbox when the animation stops. There isn’t a way that I’ve found to tell if the hitmarker exists or not because :GetMarkerReachedSignal(markerName) always returns a signal, never nil.

It should look something like this, (this doesn’t work due to the problem stated above):

local hitStopSignal = anim:GetMarkerReachedSignal("HitStop")

if hitStopSignal then
 hitStopSignal:Wait()
else
 anim.Stopped:Wait()
end

hitbox:Destroy()

You could do this

local hitStopSignal = anim:GetMarkerReachedSignal("HitStop")

local hitStopEvent
local stoppedEvent

local function disc()
    hitStopEvent:Disconnect()
    stoppedEvent:Disconnect()
    hitbox:Destroy()
end

hitStopEvent = hitStopSignal:Connect(disc)
stoppedEvent = anim.Stopped:Connect(disc)

Then if either event happens, both will be disconnected and the hitbox will be destroyed.

2 Likes

The problem arrose due to me wanting to pass the event to a function,

function stopHitBox(signal)
 signal:Wait()
 hitbox:Destroy()
end

stopHitBox(hitStopSignal or animStoppedSignal)

so that’s what I was focused on finding a solution for.

I’ll find a workaround based on what you’ve sent though, thanks.