Scripts can be used to update default animations and to add new ones. The two examples covered by this course will change the default run animation and will play an animation on command when a player touches an object.


Changing Default Animations
By default, Roblox characters include common animations like running, climbing, and jumping. For the first example, you’ll create a script to swap the default run animation with a more unique one. If you don’t have a run animation to practice with, you can use one of the example animations provided.
Setup the Script
So the animation swap applies to all players, the script will be stored in ServerScriptService.
-
In ServerScriptService, create a new script named ChangeRunAnimation.
-
In the script, create two variables:
Players
- Gets the Players service, giving you access to players that join the game.runAnimation
- Sets the ID of the animation to be used. For the ID, use the one made in Creating Animations, or find one from the card below.
local Players = game:GetService("Players") local runAnimation = "rbxassetid://656118852"
Need a Run Animation?
Ninja Run
656118852
Werewolf Run
1083216690
Zombie Run
616163682
Additional animations can be found in the Catalog Animations page.
-
Copy the highlighted code below. When players join the game through
PlayerAdded
, the script will check if their avatar is loaded. In the next section, you’ll add code to swap animations in theonCharacterAdded
function.local Players = game:GetService("Players") local runAnimation = "rbxassetid://616163682" local function onCharacterAdded(character) end local function onPlayerAdded(player) player.CharacterAppearanceLoaded:Connect(onCharacterAdded) end Players.PlayerAdded:Connect(onPlayerAdded)
Replace the Animation
Default animations are accessed through a player’s Humanoid object. In this case, you’ll use the humanoid to find the run animation, then swap it’s animation ID with a new one.
-
In
onCharacterAdded
, create a variable to store the humanoid.local Players = game:GetService("Players") local runAnimation = "rbxassetid://616163682" local function onCharacterAdded(character) local humanoid = character:WaitForChild("Humanoid") end local function onPlayerAdded(player) player.CharacterAppearanceLoaded:Connect(onCharacterAdded) end Players.PlayerAdded:Connect(onPlayerAdded)
-
Attached to the humanoid is a script named Animate, where default animations are parented. Store this in a variable named animateScript.
local Players = game:GetService("Players") local runAnimation = "rbxassetid://616163682" local function onCharacterAdded(character) local humanoid = character:WaitForChild("Humanoid") local animateScript = character:WaitForChild("Animate") end local function onPlayerAdded(player) player.CharacterAppearanceLoaded:Connect(onCharacterAdded) end Players.PlayerAdded:Connect(onPlayerAdded)
-
Accessing different animations can be done using the dot operator, such as
animateScript.run
. To change the run, set the animation ID to the one stored inrunAnimation
.local Players = game:GetService("Players") local runAnimation = "rbxassetid://616163682" local function onCharacterAdded(character) local humanoid = character:WaitForChild("Humanoid") local animateScript = character:WaitForChild("Animate") animateScript.run.RunAnim.AnimationId = runAnimation end local function onPlayerAdded(player) player.CharacterAppearanceLoaded:Connect(onCharacterAdded) end Players.PlayerAdded:Connect(onPlayerAdded)
Changing Other Animations
A few of the most common animations are listed below:
animateScript.climb.ClimbAnim
animateScript.sit.SitAnim
animateScript.fall.FallAnim
animateScript.swim
animateScript.idle.Animation1
animateScript.walk.WalkAnim
Remember to access each one using
.AnimationId
at the end. For a full guide on changing other default animations, see the Using Animations article. -
Test the game and notice how the default run animation has changed.
Next Page Playing Animations