Source: Roblox Creator Hub · CC BY 4.0 · View source · Code samples: MIT Imported 2026-10-03. Formatting adapted for this site.
Use animations
Once you have created an animation, you need to use scripts to include them in your game. You can either play animations manually from scripts or replace default animations for player characters.
Play animations from scripts
In some cases, you'll need to play an animation directly from inside a script, such as when a user presses a certain key or picks up a special item.
Humanoids
To play an animation on a rig containing a Humanoid object, such as typical playable characters, follow this basic pattern:
- Ensure that the local player's
Humanoidcontains anAnimatorobject. - Create a new
Animationinstance with the properAnimationId. - Load the animation via
Animator:LoadAnimation()to create anAnimationTrack. - Play the track with
AnimationTrack:Play().
For example, the following LocalScript, when placed in StarterPlayerScripts, loads a "kick" animation onto the player's character and plays it. The script also utilizes the GetMarkerReachedSignal() method to detect when a specific animation event occurs.
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- Ensure that the character's humanoid contains an "Animator" object
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Create a new "Animation" instance and assign an animation asset ID
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- Load the animation onto the animator
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- If a named event was defined for the animation, connect it to "GetMarkerReachedSignal()"
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)
task.wait(4)
-- Play the animation track
kickAnimationTrack:Play() Non-humanoids
To play animations on rigs that do not contain a Humanoid, you must create an AnimationController with a child Animator. For example, the following Script (assumed to be a direct child of the rig) loads a "kick" animation and plays it.
local rig = script.Parent
-- Create a new "Animation" instance and assign an animation asset ID
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- Create a new "AnimationController" and "Animator"
local animationController = Instance.new("AnimationController")
animationController.Parent = rig
local animator = Instance.new("Animator")
animator.Parent = animationController
-- Load the animation onto the animator
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- If a named event was defined for the animation, connect it to "GetMarkerReachedSignal()"
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)
task.wait(4)
-- Play the animation track
kickAnimationTrack:Play() Replace default animations
By default, Roblox player characters include common animations like running, climbing, swimming, and jumping. You can replace these default animations with animations from the catalog or with your own custom animations.
Obtain the asset ID of the new animation as follows:
- For a custom animation built with the Animation Editor, follow the export instructions.
- Copy an appropriate ID from the catalog animation reference below. For example, to replace the default run animation with the Ninja Run variant, use
656118852.
In the Explorer window, add a new
Scriptto ServerScriptService.- Hover over ServerScriptService and click the ⊕ button.
- From the contextual menu, insert a Script.
In the new script, paste the following code:
local Players = game:GetService("Players") local function onCharacterAdded(character) -- Get animator on humanoid local humanoid = character:WaitForChild("Humanoid") local animator = humanoid:WaitForChild("Animator") -- Stop all animation tracks for _, playingTrack in animator:GetPlayingAnimationTracks() do playingTrack:Stop(0) end local animateScript = character:WaitForChild("Animate") --animateScript.run.RunAnim.AnimationId = "rbxassetid://" --animateScript.walk.WalkAnim.AnimationId = "rbxassetid://" --animateScript.jump.JumpAnim.AnimationId = "rbxassetid://" --animateScript.idle.Animation1.AnimationId = "rbxassetid://" --animateScript.idle.Animation2.AnimationId = "rbxassetid://" --animateScript.fall.FallAnim.AnimationId = "rbxassetid://" --animateScript.swim.Swim.AnimationId = "rbxassetid://" --animateScript.swimidle.SwimIdle.AnimationId = "rbxassetid://" --animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://" end local function onPlayerAdded(player) player.CharacterAppearanceLoaded:Connect(onCharacterAdded) end Players.PlayerAdded:Connect(onPlayerAdded)For each line that references a default character animation, uncomment it and paste the replacement ID after
rbxassetid://. For example, to change the default run animation to the Ninja Run variant:local Players = game:GetService("Players") local function onCharacterAdded(character) -- Get animator on humanoid local humanoid = character:WaitForChild("Humanoid") local animator = humanoid:WaitForChild("Animator") -- Stop all animation tracks for _, playingTrack in animator:GetPlayingAnimationTracks() do playingTrack:Stop(0) end local animateScript = character:WaitForChild("Animate") animateScript.run.RunAnim.AnimationId = "rbxassetid://656118852" --animateScript.walk.WalkAnim.AnimationId = "rbxassetid://" --animateScript.jump.JumpAnim.AnimationId = "rbxassetid://" --animateScript.idle.Animation1.AnimationId = "rbxassetid://" --animateScript.idle.Animation2.AnimationId = "rbxassetid://" --animateScript.fall.FallAnim.AnimationId = "rbxassetid://" --animateScript.swim.Swim.AnimationId = "rbxassetid://" --animateScript.swimidle.SwimIdle.AnimationId = "rbxassetid://" --animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://" end local function onPlayerAdded(player) player.CharacterAppearanceLoaded:Connect(onCharacterAdded) end Players.PlayerAdded:Connect(onPlayerAdded)
Set animation weights
You can use multiple animations for the same action. For example, there are two idle variations in the code sample for replacing default animations.
When multiple animations exist for a character state, the Animate script randomly chooses which one to play, but you can influence the outcome by setting the animation's Weight value under the following formula:
- animation weight / total weight of all state animations
In the following example, idle.Animation1 will play ⅓ of the time the character is idle, while idle.Animation2 will play ⅔ of the time.
animateScript.idle.Animation1.AnimationId = "rbxassetid://656117400"
animateScript.idle.Animation2.AnimationId = "rbxassetid://656118341"
animateScript.idle.Animation1.Weight.Value = 5
animateScript.idle.Animation2.Weight.Value = 10 Animation references
Default character animations
The following table contains all of the default character animations that you can replace with catalog animations or your own custom animations. Note that Idle has two variations which you can weight to play more or less frequently.
| Character action | Animate script reference |
|---|---|
| **Run** | `animateScript.run.RunAnim.AnimationId` |
| **Walk** | `animateScript.walk.WalkAnim.AnimationId` |
| **Jump** | `animateScript.jump.JumpAnim.AnimationId` |
| **Idle** | `animateScript.idle.Animation1.AnimationId` `animateScript.idle.Animation2.AnimationId` |
| **Fall** | `animateScript.fall.FallAnim.AnimationId` |
| **Swim** | `animateScript.swim.Swim.AnimationId` |
| **Swim (Idle)** | `animateScript.swimidle.SwimIdle.AnimationId` |
| **Climb** | `animateScript.climb.ClimbAnim.AnimationId` |
Catalog animations
When using avatar animation bundles to replace default animations, use the following references for the respective asset IDs. For example, if you want to apply the Ninja Jump animation, use 656117878. Note that Idle has multiple variations.
| **Astronaut** | Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb Run Walk Jump Idle Fall Swim Swim (Idle) Climb |