Lesson 01 of 05
Loading and Playing Animations
Load animations from the cloud, play them on any humanoid, and control playback.
Animations in Roblox are assets stored in the cloud, referenced by an Animation instance with an AnimationId. To play one:
- 1.Get the Animator from the Humanoid
- 2.Load the animation with :LoadAnimation()
- 3.Call :Play() on the returned AnimationTrack
AnimationTrack properties
- Speed — playback speed multiplier
- Looped — whether it repeats
- IsPlaying — whether it's currently running
- TimePosition — current frame position
- Length — total duration in seconds
Always load animations once and cache the track. Loading is expensive — doing it every time you want to play is a common performance mistake.
luau
1-- Get the Animator (modern approach)
2local humanoid = character:WaitForChild('Humanoid')
3local animator = humanoid:WaitForChild('Animator')
4
5-- Create and load the animation
6local animAsset = Instance.new('Animation')
7animAsset.AnimationId = 'rbxassetid://YOUR_ANIM_ID'
8
9local track = animator:LoadAnimation(animAsset)
10
11-- Configure and play
12track.Priority = Enum.AnimationPriority.Action
13track.Looped = false
14track:Play(0.1) -- 0.1s fade-in
15
16-- Wait for it to finish
17track.Ended:Wait()
18print('Animation complete')
19
20-- Or connect to completion
21track.Stopped:Connect(function()
22 print('Track stopped')
23end)
READY · 23 lines
