Skip to content

Animation

System · Animation · server and client scripts

Animation has the numbers scripts need to write a character's Animator.Layers: the first layer scripts may write and the limb mask flags. Layers 1 through 4 play the built-in clips idle, walk, jump, tread, swim, sit, climb, and hang; layers FirstScriptLayer through 8 are free for scripts.

To turn a limb on top of whatever plays, give its body part a LimbPose, which has one Rotation. Rotation.fromEuler builds one from YXZ Euler angles in degrees, and a positive pitch swings a limb forward, so Rotation.fromEuler(Vector3.new(90, 0, 0)) holds an arm straight out in front. A PoseWeight on the character scales every LimbPose it has, from 0 to 1.

Scripts written for API 54 turn limbs through World.Query("PoseOffset"), one rotation per limb plus Weight. At API 54 that query still works and writes LimbPose and PoseWeight; at API 58 it raises an error.

FirstScriptLayer

PropertyRead only
FirstScriptLayer: number

FirstScriptLayer is the lowest Animator.Layers index a script may write. Writing a lower layer raises an error.

Example

-- Server script: every new character sits down.
Component.Animator.Added:Connect(function(character: Entity)
    local animator = character.Animator
    if animator then
        animator.Layers[Animation.FirstScriptLayer] = { Clip = "sit" }
    end
end)

GetJoints

Function
GetJoints() -> {{Name: string, Parent: string?, Pivot: vector}}

GetJoints returns the joints of the character rig, each parent before its children. Each joint has its Name, its Parent joint name (nil for Root), and the Pivot where it sits in the rig's bind pose, measured from the character's origin. A limb turns about its pivot: the torso bends at the waist (0, -1, 0) and carries the head and arms, the shoulders are at (±1.5, 0.5, 0) on the arm's own axis, and the hips hang from Root at (±0.5, -1, 0) so a bent torso leaves the legs where they stand.

Example

-- Server script: print where each limb of the rig turns.
for _, joint in Animation.GetJoints() do
    print(joint.Name, joint.Parent, joint.Pivot)
end

Part

PropertyRead only
Part: { [string]: number }

Part has the limb flags for the Mask of an animation layer. A masked layer moves only those limbs; the rest of the body keeps playing the lower layers.

Example

-- Server script: new characters climb with their arms only.
local arms = bit32.bor(Animation.Part.LeftArm, Animation.Part.RightArm)
Component.Animator.Added:Connect(function(character: Entity)
    local animator = character.Animator
    if animator then
        animator.Layers[Animation.FirstScriptLayer] = {
            Clip = "climb",
            Mask = arms,
            Loop = true,
        }
    end
end)
Value Code Description
Head 1 The head.
Torso 2 The torso.
LeftArm 4 The left arm.
RightArm 8 The right arm.
LeftLeg 16 The left leg.
RightLeg 32 The right leg.