Tool play animation

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local anim = script.Parent.Animation

script.Parent.Equipped:connect(function()
mouse.Button1Down:Connect(function()
local animTrack = player.Character.Humanoid:LoadAnimation(anim)
animTrack:Play()  
print("Animation")
end)
end)

script.Parent.Unequipped:connect(function()

end)

This local script is in a tool. The tool also has an Animation in it which is called “Animation”. I do not know why it is not playing that animation once the player has the tool out. Can someone please help me?

1 Like

Is it printing “Animation”? and you have your code so you have to left click so you are doing that right?

yes, I am doing that. It is not working. Is there some better way to do it? Once I have the tool toggled it should play an animation.

Well if you’re trying to play the animation on a left click you could use the Activated event instead of the mouse Button1Down event

idk I saw on youtube and I used his script since it worked. My old script didn’t. Idk I’m confused.

Are there any errors? Because it should work

Try this if you want:

local anim = script.Parent:WaitForChild("Animation")

script.Parent.Activated:Connect(function()
	local char = script.Parent.Parent
	
	char.Humanoid:LoadAnimation(anim):Play()
	
	print("Animation")
end)
local tool = script.Parent
local anim = tool:WaitForChild("Animation") 
local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid") 
local loadanim = humanoid:LoadAnimation(anim)

tool.Activated:Connect(function()
	
	loadanim:Play()
end)

This is in a local script right? It is not working.

So no errors and it prints “Animation” when you left click, but the animation does not play? If so it might be a problem with the priority of the animation

It prints nothing. It has no errors related to the script. Mybe the script doesn’t work since I have this animation saved under my username not group?

Can you send a picture of the tool in the heirachy?

You need to at least have a part named “Handle” in there
image

U can set false. You don’t need it. Nvm it works. I forgot to set it to false. But the animation glitches. For example if you click out of it the animation doesn’t stop

Well… can I see your code now? If it’s the same as the original one or the one I sent you it should at least print something when you left click with it equip

i used mine. Let me try urs. Give me a second

But the animation is broken. The one which I made doesn’t show in the animation once using the part

Oh nevermind you dont need to do that I didn’t see your edit you just have to stop the animation when the tool is unequipped

robloxapp-20230418-1700570.wmv (2.3 MB)

Look at thesen videos you notice big differences in how the animations are played.

robloxapp-20230418-1702471.wmv (1.8 MB)