How can I know how an animation stopped?

OK SO
I am trying to make a battle system. for this I’m using the KeyframeReached event. One of the uses for this is to check if, once the animation stops, if it was interrupted or it just ended, with a bool that is set to true on the last keyframes. HOWEVER, for some reason, sometimes it is not setting, meaning it is not reading that keyframe. This being said, I’m looking for an alternative solution to check if the animation ended or not.
Sample code (this runs after a remote):

function module.Roll(P1)
    local Ended = false
    local AnimationTrack = nil
    local KeyframeConnection = nil
    local StoppedConnection = nil
    local P1BattleFolder = P1:WaitForChild("BattleSystem")
    local P1Weapon = P1:WaitForChild("Weapon")
    local P1Character = P1.Character
    local P1Humanoid = P1Character.Humanoid
    local P1Animator = P1Humanoid:WaitForChild("Animator")
    local CanCancel = P1BattleFolder.CanCancel
    local IsInvincible = P1BattleFolder.IsInvincible
 
    AnimationTrack = P1Animator.AnimationPlayed:Wait()
    
    ChangeState(P1, "Roll")
    CanCancel.Value = false
    
    KeyframeConnection = AnimationTrack.KeyframeReached:Connect(function(keyframe)
        if keyframe == "MovementBegin" then
            IsInvincible.Value = true
        elseif keyframe == "MovementEnd" then
            IsInvincible.Value = false
        elseif keyframe == "AnimationEnd" then
            print("Roll Ended")
            Ended = true
        end
    end)
    
    StoppedConnection = AnimationTrack.Stopped:Connect(function()
        CanCancel.Value = false
        print(Ended)
        if Ended then
            P1BattleFolder.Priority.Value = 0
            ChangeState(P1, "Idle")
        end
        KeyframeConnection:Disconnect()
        StoppedConnection:Disconnect()
    end)
end

TLDR: Im looking for an alternative method to setting the bool to true when the animation ends.

Edit 1: I believe what is causing the issue is a varying delay between the StoppedConnection and the AnmationEnd keyframe

If you already have a loaded animation, you can use AnimationTrack.Stopped to detect if the animation has stopped

(Do AnimationTrack.Stopped:Wait() which will yield until the animation has stopped)

1 Like

But there is a problem with that. As you can see, in the sample I use a connection (which does about the same, I should change it) BUT my problem is detecting if the stopped happened because it was stopped or because the animation really got to the end.

I don’t think it’s possible to do that. The only way is to use keyframes and set boolvalues.

Perhaps GetMarkerReachSignal is more precise?

1 Like

Tried it out, results were the same.

There is a function called stopped:

Animation.Stopped:Wait()

(Sorry for being late)

1 Like