Playing an animation from a local script

How would I do so in playing an animation in a local script. Here is what I have going on so far.

local Plane = game.ReplicatedStorage.Plane:Clone()
Plane.Parent = game.workspace.CurrentCamera

local function Animation1()
	local Human = Plane:WaitForChild("Humanoid")
	local Animator = Human:FindFirstChildOfClass("Animator")
	local Track = Instance.new("Animation") 
	Track.Parent = game.Workspace
	Track.AnimationId = "rbxassetid://12190507218"
	local Anim = Human.Animator:LoadAnimation(Track)
	Anim:Play() 
end

Animation1()

This local script is in StarterPlayerScripts.

I currently have a model which is cloned for every player. And as soon as it is cloned I want an animation to be played on this model. What I have right now doesn’t seem to be working and am not sure why. I would appreciate some help, thank you!

First, i can see you used game.workspace. You should use workspace or game.Workspace (capital letter)
Second, you are cloning your model into workspace.CurrenrCamera.
Then, you define Char value, which is a model, but you are trying to search for it in workspace. Is it the same model you cloned?

Try:

local Model = game.ReplicatedStorage.Model:Clone() Model.Parent = game.workspace.CurrentCamera

local Track = Instance.new("Animation") 
Track.Parent = workspace 
Track.AnimationId = "rbxassetid://12190507218"
local Anim = Model:WaitForChild("Humanoid").Animator:LoadAnimation(Track) Anim:Play() 

2 Likes

Thanks for the response but that didn’t seem to work. The model was cloned but didn’t end up playing the animation. And yes the model I cloned is the model I want the animation to be played on.