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