Trigger script at specific animation time

I tried

animation:play()
if animation.timeposition = 1 then
play:audio()
end

It didn’t work, maybe I did it wrong

I don’t know how I can trigger a script at a specific time of an animation.

Sure, I can use wait(1) and it will work, but when I have to cancel the animation, the script will still work after the wait code.

I want to trigger script at specific animation time

1 Like

You need to check TimePosition in a loop like this:

animation:Play()
repeat
   task.wait()
until math.floor(animation.TimePosition) == 1
play:audio()

Also be careful about capitalization as timeposition is incorrect
Remove the math.floor if you want to check for 0.5 for example but you’ll need to use >= instead of ==

2 Likes

You can use Animation Events to connect a function

1 Like

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