Why does this animation script not work?

I’m making a pretty simple script, following this tutorial: Roblox Scripting Tutorial: How to Script a Tool Animation - YouTube
and my script is

local Tool = script.Parent
local Animation = Tool.Animation
Tool.Activated:Connect(function()
	local Character = Tool.Parent
	local humanoid = Character.Humanoid
	local AnimationTrack = humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
end)

I am not getting any errors in the output. My hierarchy is as follows:
Screen Shot 2021-04-05 at 1.39.41 PM
I’ve put my animations ID into the Animation.AnimationId property.

Check to make sure that the AnimationPriority is set to Action, also use a WaitForChild() function when defining your Humanoid?

should I do

	local humanoid = Character:WaitforChild("Humanoid")

?
Also, I did make sure it was set to action.

Yeah, also do make sure that the animation that you’re playing is owned by you

Otherwise I believe it won’t work

It is owned by me, also, I get the error
WaitforChild is not a valid member of Model “Workspace.nicknickphoenix”

1 Like

I recommend you to play the animation in a client script.

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Tool = script.Parent
local Animation = Tool.Animation

Tool.Activated:Connect(function()
	AnimationTrack:Play()
end)

Oh I maybe see the issue then?

Could you try this?

local Tool = script.Parent
local Animation = Tool.Animation
local Character

Tool.Activated:Connect(function()
	local humanoid = Character:WaitForChild("Humanoid")
	local AnimationTrack = humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
end)

Tool.Equipped:Connect(function()
    Character = Tool.Parent
    print(Character)
end)

I keep forgetting that you need to play animations on the client when using Humanoid:LoadAnimation

You still can play animations on the server but I think it would just delay more.

If I do it on the client, wouldn’t that mean other people can’t see the animation?

Well no because the animation have network ownership over their character so it would replicate because it operates on motor 6d.

Short answer: everyone still can see the animation

1 Like

I copy pasted your script (into the same server script you saw in the heriarchy) and it still doesn’t work. AnimationId is rbxassetid://6641902258 if that helps at all.

Try mine, and use that in a local script. (Message 5)

Really now? Are you getting anything from your Output at all?

nope. apart from where it prints my name

Try this:

local Tool = script.Parent
local Animation = Tool.Animation
local Character = Tool.Parent
local humanoid = Character:WaitForChild("Humanoid")
local AnimationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(Animation)

Tool.Activated:Connect(function()
     AnimationTrack:Play()
end)

This item is deprecated. Do not use it for new work.
Humanoid | Roblox Creator Documentation

doing

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local Tool = script.Parent
local Animation = Tool.Animation
local humanoid = Tool.Parent
Tool.Activated:Connect(function()
	local humanoid = Tool.Parent.Humanoid
	local AnimationTrack = humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
end)

does not work, however it doesn’t show any error.

Would this be in a server script or local script?

If the script does not have something else like doing something on the server, use localscript, if not normal script (it really does not matter)

1 Like

Pasting what you did on a local script didn’t work, however I got this warning:

Infinite yield possible on ‘Players.nicknickphoenix.Backpack:WaitForChild(“Humanoid”)’

Ok wait, where exactly are you placing the script? In the Tool Object? Or the Tool Handle? OR THE TOOL MESH WUT

1 Like