This is local script in the tool and it is not working properly, it plays animation after tool is unequipped. I think I need to add "check if tool is equipped" but I don't know how to do it.
local Tool = script.Parent local Player = game.Players.LocalPlayer local Character = Player.Character or script.Parent local Humanoid = Character.Humanoid local UserInputService = game:GetService("UserInputService") local AnimationID = 'rbxassetid://4868889544' local Animation = Instance.new("Animation") Animation.AnimationId = AnimationID local LoadAnimation = Humanoid:LoadAnimation(Animation) local key = 'R' local debounce = true -- how to check if tool is equipped? Tool.Equipped:Connect(function() UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end if Input.KeyCode == Enum.KeyCode[key] and debounce == true then debounce = false LoadAnimation:Play() wait(3) debounce = true end end) end) -- how to check if tool is unequipped? Tool.Unequipped:Connect(function() LoadAnimation:Stop() LoadAnimation:Destroy() end)
You could use variables to check if the tool is equipped like this:
local Equipped = false Tool.Equipped:Connect(function() Equipped = true UserInputService.InputBegan:Connect(function(Input, IsTyping) if Equipped == true then -- Check if equipped when input begins -- Put code here end end) end) Tool.Unequipped:Connect(function() Equipped = false end)
Or alternitively you could just check tool.Parent
. A tool should be Parented to Player.Backpack
if it's unequipped and parented to their character if it's equiped.
if Tool.Parent == Player.Backpack then print("Unequipped") elseif Tool.Parent == Player.Character then print("Equipped") end