Check if an animation event has been reached or not

  1. What do you want to achieve?
    I want to check if an animation event has been reached or not. If not reached then 1 thing happen or if it has been reached then it another thing happens.

  2. What is the issue?
    I’m not quite sure where to start. I’ve fully aware that [GetMarkerReachedSignal()] exists but i’m not sure how to check if the event hasn’t been reached yet or not.

  3. What solutions have you tried so far?
    None, Like i’ve said i rly have no idea where to start. I have also checked the forum but no one has yet to ask or answer this. Any help would be very appreciated.

How to Work with Animation Events in Roblox

Setting Up Animation Events:

  1. Create your animation in the Animation Editor
  2. Right-click on the desired keyframe and select ‘Add Animation Event’
  3. Name your event (this will be your marker name)

in Code:
First, load your animation through a Humanoid’s Animator in a LocalScript:

local animator = humanoid:WaitForChild("Animator")
local animation = YOURANIMATION
local animationTrack = animator:LoadAnimation(animation)
-- Play the animation
animationTrack:Play()

To detect when a marker is reached:

animationTrack:GetMarkerReachedSignal("markerName"):Connect(function()
    print("Marker reached!")
    -- Your code here
end)

To track when a marker hasn’t been reached yet:


local markerReached = false

-- Start tracking before marker is reached
task.spawn(function()
    while not markerReached do
        -- Your code for when marker isn't reached yet
        print("Waiting for marker...")
        task.wait(0.1) 
    end
end)

-- Set up marker detection
animationTrack:GetMarkerReachedSignal("markerName"):Connect(function()
    markerReached = true
    print("Marker reached!")
end)

Note: Make sure to clean up and disconnect the getmarkerreachedsignal events when it’s done to improve performance.