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:

1local Sound = Instance.new("Sound")
2wait(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

1local animation = path.to.Animation
2local animationTrack = Humanoid:LoadAnimation(animation)
3 
4-- somewhere else in your script...
5animationTrack:Play()
6animationTrack.Stopped:Wait() -- wait for the Stopped event to fire
7print("animation stopped")

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

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

Answer this question