Need help with animating a tool

Hi, I’m trying to figure out a way to allow the animation to keep on playing, even when you are moving. For some reason, the animation stops when I move, or bump into something. If I’m moving and click on the tool, the animation will run normally. If I’m still, the animation works fine. It doesn’t work/stops working as soon as I start moving.

Here is the code.

script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
animation:Play()
end)
end)

script.Parent.Unequipped:Connect(function()
animation:Stop()
end)

If you’re still confused, this is what I mean. https://gyazo.com/aed9769ff0e04374c6b49a2157cad93c

1 Like

animation.Priority=2
Put this after animation:Play() and it should fix the issue.

game.Players.LocalPlayer.Character is a bigggggg no no.

The character could possibly not be loaded or something, so I’d do this.

Also, a more efficient way to stop all running animations in the character is in the script below in the Unequipped function.

script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
local Hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
animation = Hum:LoadAnimation(script.Parent.Animation)
animation:Play()
end)
end)

script.Parent.Unequipped:Connect(function()

local AnimationTracks = humanoid:GetPlayingAnimationTracks()

for i, track in pairs (AnimationTracks) do
	track:Stop()
end
end)``

Thank you so much; it worked! I really appreciate your help!