PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

LoadAnimation

Loads an Animation onto an Animator, returning an AnimationTrack. Used to load animations on locally controlled models (such as player characters) from the server.

A 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 BasePart/SetNetworkOwner.

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 Humanoid or AnimationController.

Note if the server has network ownership of the model, and the AnimationController or Humanoid was created on the server, then Animator/LoadAnimation does not need to be used as LoadAnimation can be used directly from the Humanoid or AnimationController on the server.

Parameters

Name Type Default Description

The Animation to be used.

Returns

Return Type Summary

The AnimationTrack created.


Code Samples


Animator LoadAnimation

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