Animation Plays When Not Holding Tool

I have a pan, and when you hold it, and then click, an animation plays.
But when you un equip it, it still plays when you click.
Can anyone help?

local mouse = player:GetMouse()
local AnimationId = "rbxassetid://5009868932" -- use your animation id

local debounce = true

script.Parent.Equipped:Connect(function()
mouse.Button1Down:Connect(function()
local Humanoid = player.Character.Humanoid

if mouse.Button1Down and debounce == true then
debounce = false
local Animation = Instance.new("Animation")
Animation.AnimationId = AnimationId
local LoadAnimation = Humanoid:LoadAnimation(Animation)

local sd = script.Parent.Sound2

LoadAnimation:Play()
wait(1)
Animation:Destroy()
debounce = true


script.Parent.Handle.Touched:Connect(function(hit)
	if hit.Name == "HumanoidRootPart" or hit.Name == "Torso" then
			sd:Play()
		end
end)
end
end)	
end)

Have you check if the Animation is in R6 or R15?

Animation is R6,
( 30 Characters)

is your character R6? you can use the animation editor to check if the animation is r6 or R15

As I said, the animation is indeed R6.

is the animation’s priority set to Action?

image
There is no way to change that. It’s all in the script.

Unequipped exists too. You could use that function and check if the animation is playing.

If it was, then destroy it.

ex:

tool:Unequipped:Connect(function()

Where would I put it in my script?

You would put it in the same script where the animation is made from an instance.

remember, the tool is a variable I made, so you would have to do script.Parent if you don’t feel like defining a variable.

Also you might not even have to check if the animation is playing or not, just destroy it if it gets unequipped.

Is there no way to just add or change something in the script so only when you’re holding the tool, and then clicking the animation plays?

I hope this helps :slight_smile:

If the animation is destroyed when the tool is not equipped, the animation won’t play as there is no animation in existence.

It’s set to action…

Sense you are calling the animation with a Script, you have to re-upload your new animation to Roblox and then grab the new animation’s Id.