Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you wait the length of an Animation?

Asked by 4 years ago

I'd like to know how this is done, because I'm not entirely sure how to do this. I know with Sounds you can do:

local Sound = Instance.new("Sound")
wait(Sound.TimeLength)

1 answer

Log in to vote
4
Answered by
Elyzzia 1294 Moderation Voter
4 years ago

you can do this with the AnimationTrack.Stopped event

AnimationTracks are the objects returned by Humanoid:LoadAnimation or AnimationController:LoadAnimation

so, to wait for the animation to fniish playing, you can do this

local animation = path.to.Animation
local animationTrack = Humanoid:LoadAnimation(animation)

-- somewhere else in your script...
animationTrack:Play()
animationTrack.Stopped:Wait() -- wait for the Stopped event to fire
print("animation stopped")

alternatively, you could just wait out the length of the animation

animationTrack:Play()
wait(animationTrack.Length)
print("animation stopped")
Ad

Answer this question