Tool's Animation Playing When Not Equipped

So I’m pretty new to tools and I need help figuring out what went wrong in my code. Basically there is a pipe that plays a swinging animation when you click but for some reason you’re still able to swing the “pipe” when the tool isn’t equipped even despite my counter measures.

local InputService = game:GetService("UserInputService")

local Tool = script.Parent
local CoolDown = false
local Equipped = false

	Equipped = true
	if Equipped == true then
		local Plr = game.Players.LocalPlayer
		local Swing = Tool.SwingAnimation
		local SwingAnim = Plr.Character.Humanoid:LoadAnimation(Swing)
		InputService.InputBegan:Connect(function(Input, Received)
			if Input.UserInputType == Enum.UserInputType.MouseButton1 and not CoolDown then
				CoolDown = true

				-- Other Code
				CoolDown = false

	Equipped = false

EDIT: Also in an attempt to find the issue using print statements I found that the function that plays the animation when you click in the first place isn’t running which I do not understand as if that were true it wouldn’t animate or even detect if you were clicking for that matter.

Is the animation yours? It won’t be playing if the animation isn’t yours and code looks pretty fine to me. Don’t forget about the animation priority too!

I think I just figured it out. The Animation is mine yes. I deleted the “if Equipped == true then” and moved it to the “if Input.UserInputType” line. Thanks for your time.

1 Like

You should also move the InputService lines outside of Tool.Equipped, otherwise its gonna fire multiple times when you click

It should? I had a print statement in there and it fired only once per click.

Each time you equip the tool it connects the InputBegan event, so every time you equip the tool, it increases the amount of times the script repeats.