In this script, after you click to swing a sword, I want it so you are unable to click for another 5 seconds, using debounce. However I simply can’t get it working and you can spam the sword (essentially, debounce isn’t working, or I’ve located the lines of code incorrectly.
wait()
local debounce = false
local tool = script.Parent
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char.Humanoid
local anim = hum:LoadAnimation(script.Parent.KatanaEquipAnim)
local attackanim = hum:LoadAnimation(script.Parent.UpdatedKatanaSwingAnim)
local mouse = player:GetMouse()
anim.Priority = Enum.AnimationPriority.Action
attackanim.Priority = Enum.AnimationPriority.Action
script.Parent.Equipped:Connect(function()
anim:Play()
end)
script.Parent.Unequipped:Connect(function()
anim:Stop()
end)
if debounce then return end
script.Parent.Activated:Connect(function()
debounce = true
attackanim:Play()
print("sword hit")
tool.Handle.Swing:Play()
wait(5)
debounce = false
end)