Issue with animationTrack:GetMarkerReachedSignal()

Hello there, I am going to get straight to the point, I have these equip and unequip tool animations, and I added animation events to the animations. I use a ManageAnimation() function to check for :GetMarkerReachedSignal()

The issue with it is that, when I equip the tool, the function works fine, it goes through the :GetMarkerReachedSignal() and everything is good. But when I unequip it, the ManageAnimation function fires, but it doesn’t go through GetMarkerReachedSignal(). I am really new to animations, so I would need your help fixing it.

Heres what you’d need:

function ManageAnimation(animationTrack,Type)
if Type=="Unsheathe"  then --this is the tool equip parameter
print("Check")
animationTrack:GetMarkerReachedSignal(Type):Connect(function()
print("Unsheathe")
ServerEvents.Equip:FireServer(sw,Tool,requiredCFrame)
unsheathe2:Play()
end)

elseif Type=="Sheathe" then -- tool unequip parameter
print("Check1")
animationTrack:GetMarkerReachedSignal(Type):Connect(function()
print("Sheathe")
ServerEvents.UnEquip:FireServer(sw,Tool)
end)
end
end
  1. What solutions have you tried so far?
    I tried using KeyframeReached, didn’t work either.

Output when you equip:

Check
Unsheathe

Output when you unequip:

Check1

Your function ManageAnimation is set up to listen for animation markers. However, the GetMarkerReachedSignal(Type):Connect() function only connects the function to the event. If the marker has already been reached by the time you connect the function, it will not fire.

The “Unsheathe” event seems to be working as expected. However, for the “Sheathe” event, it might be that the marker is reached before you connect to the event.

You could try moving the ManageAnimation function call to a point in your code where it happens before the animation plays.

local animationTrack -- assumed to be declared earlier in your code

Tool.Equipped:Connect(function()
    ManageAnimation(animationTrack, "Unsheathe")
end)

Tool.Unequipped:Connect(function()
    ManageAnimation(animationTrack, "Sheathe")
end)

This way, you make sure that the listeners are set before the animations are played.

If the issue persists, it could be that the “Sheathe” marker is not correctly set in the animation itself, or there’s a problem with the animation. You could double-check the animation to see if everything is set correctly.

1 Like

I have double-checked as you said, and yeah I made sure the ManageAnimation function was called before the AnimationEvent was reached, I checked this through output, I do not think it is the right fix.

does it give any error code? if so please replay here

No error codes in the output,


That’s the “Sheathe” animation event at the end.

I was able to use a different method to do this, I used a function suggested by one of my friends.

local function PlayKeyframeCallback(animation,Position, Callback)
  local Animation = animation
  while (task.wait() and Animation.IsPlaying) do
    if (Animation.TimePosition >= Position) then
      if (Callback) then coroutine.wrap(Callback)() end
      break
    end
  end
end

And then

PlayKeyframeCallback(unsheathe1,animationTrack:GetTimeOfKeyframe(Type))

This works perfectly, though I know it is a different method. I thank you for your effort in trying to help @GTX_3 , also what you said earlier is correct, so you deserve the solution, as someone might come across this topic and use some help from your post.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.