Animation won't play when equipping tool

Greetings , Developers!

I am learning about tools and came to a problem. After reading the Hub and viewing some YouTube tutorials, i decided to try and put an animation whenever the user equips the tool, but nothing happens.
Here is the script i’ve worked with :

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid")
local anim = h:LoadAnimation(script.Parent:WaitForChild("Equip"))

local tool = script.Parent

tool.Equipped:Connect(function()
 anim:Play()
end)

tool.Unequipped:Connect(function()
 anim:Stop()
end)

And here it should look when played
https://gyazo.com/b48f5bebed47f4c473ad94e0a3a9442b

The Animation Priority is set to Action and the layout of the tool is image

Thank you everyone for helping :heart:

3 Likes

In order to get the LocalPlayer, you need to utilize a LocalScript, not a regular one. Generally, when ever you code anything on the client, use LocalScripts, as they were specifically designed for client/player code; including tools.

8 Likes

Gyazo links don’t embed here on the forum however you can paste the file really easy.

Does it not play at all? Does the first part play, then when it’s done it goes back to the default tool holding animation? edit: I just realized you’re using a server script, not a local script. You can’t play animations on the server unless you use a remote event, and you can’t get the local player either

@C_Sharper @iiFusionzX
I am truly sorry for that tiny mistake. Honestly it was around 2 am when i saw the problem.
However the animation works know but how can i make it maintain the last pose of the animation instead of coming back to the original holding animation?
https://gyazo.com/42f6cd7baa7decbc3ec647e996bd0bee

Did you make the animation movement or idle?

1 Like

Because if not, that might be the case.

You can use animationtrack.Stopped:Wait() and then play an idle holding animation.

Yay it works. Thank youu :heart: