Animation onto an
Animator, returning an
AnimationTrack. Used to load animations on locally controlled models (such as player characters) from the server.
Model is considered locally controlled if it has network ownership of the model, clients have network ownership of the local character model by default and other models can be assigned to a different client using
It is best practice to only animate a model from the server if the server has network ownership, and for this reason most developers will not need to use the
Animator/LoadAnimation function as they can load animations directly from the
Note if the server has network ownership of the model, and the
Humanoid was created on the server, then
Animator/LoadAnimation does not need to be used as
LoadAnimation can be used directly from the
AnimationController on the server.
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 a
LocalScript) or on the server (via a
Animator is a descendant of a Humanoid or AnimationController in a Player’s
Player/Character|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.
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”).
Animating a Model Locally
This code sample includes a function that can be used to play an animation on a locally controlled model (such as a player character) from the server.
local function playAnimationFromServer(character, animation) local humanoid = character:FindFirstChildOfClass("Humanoid") if humanoid then -- need to use animation object for server access local animator = humanoid:FindFirstChildOfClass("Animator") if animator then local animationTrack = animator:LoadAnimation(animation) animationTrack:Play() return animationTrack end end end