This function loads an
Animation onto an
AnimationController, returning an
AnimationTrack that can be used for playback.
How to load an Animation
The following code can be used to load an
Animation onto an
local animationTrack = animationController:LoadAnimation(animation) animationTrack:Play()
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
Script). If an
AnimationController is created on the server, its animations should be loaded and played on the server unless a player has been assigned network ownership of the
Model's root part using
BasePart/SetNetworkOwner. If an
AnimationController is created on the client it should be animated by the client.
Although it is not recommended, if a developer wishes to play animations on a locally controlled
Model from the server they can use the
Note this differs slightly for animations playing on Player characters, for more information on this please see
This code sample demonstrates how an
AnimationController can be used in place of a
Humanoid for non player character objects.
A basic rig is loaded using
InsertService and the default
Humanoid is replaced with an
AnimationTrack is then created and played.
local InsertService = game:GetService("InsertService") -- Load a model for demonstration local npcModel = InsertService:LoadAsset(516159357):GetChildren() npcModel.Name = "NPC" npcModel.PrimaryPart.Anchored = true npcModel:SetPrimaryPartCFrame(CFrame.new(0, 5, 0)) npcModel.Parent = workspace -- Replace the humanoid with an animationcontroller local humanoid = npcModel:FindFirstChildOfClass("Humanoid") humanoid:Destroy() local animationController = Instance.new("AnimationController", npcModel) -- Create and load an animation local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/asset/?id=507771019" -- Roblox dance emote local animationTrack = animationController:LoadAnimation(animation) -- Play the animation animationTrack:Play()