AnimationController

Show Deprecated

An object which allows animations to be loaded and applied to a character or model in place of a Humanoid when a Humanoid is not needed. Creates an Animator and loads animations to update Motor6Ds of said character to react in the way that is described within the animation asset referenced by an Animation object.

Should I load an Animation on the client or server?

In order for AnimationTracks to replicate correctly, it's important to know when they should be loaded on the client (via aLocalScript) or on the server (via a Script).

If an Animator is a descendant of a Humanoid or AnimationController in a Player's Character then animations started on that Player's client will be replicated to the server and other clients.

If the Animator is not a descendant of a player character, its animations must be loaded and started on the server to replicate.

The Animator object must be initially created on the server and replicated to clients for animation replication to work at all. If an Animator is created locally, then AnimationTracks loaded with that Animator will not replicate.

Both Humanoid:LoadAnimation() and AnimationController:LoadAnimation() will create an Animator if one does not already exist. When calling LoadAnimation from LocalScripts you need to be careful to wait for the Animator to replicate from the server before calling LoadAnimation if you want character animations to replicate. You can do this with WaitForChild("Animator").

See also:

  • Animation Editor to explore this powerful built-in plugin for creating custom animations
  • Using Animations to learn how to add pre-built and custom animations to your game

Code Samples

Using an AnimationController to animation non-player objects

1local InsertService = game:GetService("InsertService")
2
3-- Load a model for demonstration
4local npcModel = InsertService:LoadAsset(516159357):GetChildren()[1]
5npcModel.Name = "NPC"
6npcModel.PrimaryPart.Anchored = true
7npcModel:SetPrimaryPartCFrame(CFrame.new(0, 5, 0))
8npcModel.Parent = workspace
9
10-- Replace the humanoid with an animationcontroller
11local humanoid = npcModel:FindFirstChildOfClass("Humanoid")
12humanoid:Destroy()
13local animationController = Instance.new("AnimationController")
14animationController.Parent = npcModel
15
16-- Create and load an animation
17local animation = Instance.new("Animation")
18animation.AnimationId = "http://www.roblox.com/asset/?id=507771019" -- Roblox dance emote
19local animationTrack = animationController:LoadAnimation(animation)
20
21-- Play the animation
22animationTrack:Play()

Summary

Properties

Events

Methods

Properties

Events

Methods