I inserted local script in the tool and now it plays animation when I press "R", but it still plays animation after tool is unequipped, how to fix that? my current script:
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 key = 'R' local debounce = true UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end if Input.KeyCode == Enum.KeyCode[key] and debounce == true then debounce = false local Animation = Instance.new("Animation") Animation.AnimationId = AnimationID local LoadAnimation = Humanoid:LoadAnimation(Animation) LoadAnimation:play() wait(5) debounce = true end end)
You could do something like this:
local enabled = false UserInputService.InputBegan:Connect(function(Input, IsTyping) If IsTyping or not enabled then return end -- code end) tool.Equipped:Connect(function() enabled = true end) tool.Unequipped:Connect(function() enabled = false end)
Basically this lets you know if the player has the tool equipped.
You could try using the Tool.Unequipped
event! This fires every time a tool is unequipped. You can read about Tool.Unequipped
here!