How to run some code only if the animation reaches the event, else do nothing

as the title says, i want to activate a hitbox only if the animation event is reached, but the thing is the animation can be cancelled because its an ability with windup and other players can hit you to stop it, any ideas on how to do it?

anyone have any ideas? (character limit)

1 Like

pretty please give me some ideas

What have you tried so far? and what are you trying to reach exactly.

i have an ability that can be canceled while its winded up, the only problem is, if you do cancel it, it wont work again when you try it, with no errors

can you show a bit of your code?

Can the animation be canceled after the hitbox is activated once the animation reaches the event?

To run code only when a specific animation event is reached, you can utilize the AnimationTrack’s Stopped event. This event is fired when the animation finishes playing or is explicitly stopped.

Here’s an example of how you can achieve this in Roblox:

local humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
local animation = humanoid:LoadAnimation(script.Animation) -- Replace "script.Animation" with the path to your animation

local function onAnimationStopped()
    -- Code to be executed when the animation is stopped or finished
    -- This could include activating the hitbox or performing other actions
    -- ...
    print("Animation stopped")
end

animation.Stopped:Connect(onAnimationStopped)

-- Play the animation
animation:Play()

In this example, we assume that the script is a child of the character model. We first obtain the humanoid and load the desired animation using the LoadAnimation function. Then, we define the onAnimationStopped function, which contains the code you want to execute when the animation stops.

By connecting the Stopped event of the animation to onAnimationStopped, the code inside the function will be executed only when the animation reaches its end or is explicitly stopped.

You can modify the onAnimationStopped function to include the specific code you need, such as activating the hitbox or performing any other desired actions.

Remember to replace "script.Animation" with the actual path to your animation within the character model.

no it cannot be canceled after the windup phase