I'm trying to make a script for a tool where pressing the X button would only play the animation if my tool was equipped. Problem is, when i unequipped the tool i can continue to press x again and the animation would still play.
-//Services
local UIS = game:GetService('UserInputService')
--//Variables
local tool = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character
--//Use this since it's a local script inside a tool
player.CharacterAdded:Connect(function(character)
char = character
local hum = char:WaitForChild('Humanoid')
--//Animation
local spinSlash = hum:LoadAnimation(tool.Animation) -- i have the animation inside the tool.
--//Equipped
tool.Equipped:Connect(function()
--//Input
local debounce = false
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.X and not debounce then
debounce = true
spinSlash:Play()
wait(2)
debounce = false
end
end)
end)
--//Unequipped
tool.Unequipped:Connect(function()
spinSlash:Stop()
end)
end)
Again, i only want the x button to play the animation when the tool is equipped.

5 comments
first of all you should never repost your questions especially if they were moderated
Last time i checked it wasn't moderated, plus what's wrong with reposting a question that i've been struggling with for a whole week already?
^ it will be classed as a duplicate and moderated again.
Great, so my question will never get an answer...thanks scripting "helpers"
And the last time that i checked the community guidelines, there are no rules saying you can't repost or make duplicates, it's not like i'm spamming the post, infact i've reposted this about 4 times already and each time i did it i waited atleast a day or 2 before reposting it again only to get no answers.