As the title says, I am having trouble making it debounce. Thank you for helping me.
ply = game.Players.LocalPlayer repeat wait() until ply.Character char = ply.Character mouse = ply:GetMouse() local debounce = false local CanDamage = false anim = { equip= "rbxassetid://1007180526", leftpunch = "rbxassetid://1007372513", } equip = Instance.new("Animation", char.Humanoid) equip.Name = "Equip" equip.AnimationId = anim.equip lpunch = Instance.new("Animation", char.Humanoid) lpunch.Name = "LeftPunch" lpunch.AnimationId = anim.leftpunch combat = false function combats() local ran = math.random(1) if ran == 1 then char.Humanoid:LoadAnimation(lpunch):Play() end end function key(key) key = key:lower() if key == "2" and combat == false then print("hi") equips = char.Humanoid:LoadAnimation(equip) equips:Play() combat = true elseif key == "2" and combat == true then equips:Stop() combat = false end end enabled = true function punch(key) if combat == true and enabled == true then combats() enabled = true end end mouse.keyDown:connect(key) mouse.Button1Down:connect(punch)
What you want to do is create a bool variable right before the function, then when it fire, check if the bool is true if so make it false, at the end of the function wait a few seconds then make the bool true
ply = game.Players.LocalPlayer repeat wait() until ply.Character char = ply.Character mouse = ply:GetMouse() local debounce = false local CanDamage = false anim = { equip= "rbxassetid://1007180526", leftpunch = "rbxassetid://1007372513", } equip = Instance.new("Animation", char.Humanoid) equip.Name = "Equip" equip.AnimationId = anim.equip lpunch = Instance.new("Animation", char.Humanoid) lpunch.Name = "LeftPunch" lpunch.AnimationId = anim.leftpunch combat = false function combats() local ran = math.random(1) if ran == 1 then char.Humanoid:LoadAnimation(lpunch):Play() end end function key(key) key = key:lower() if key == "2" and combat == false then print("hi") equips = char.Humanoid:LoadAnimation(equip) equips:Play() combat = true elseif key == "2" and combat == true then equips:Stop() combat = false end end enabled = true local d = true --debounce function punch(key) if d==true then d=false --check debounce if combat == true and enabled == true then combats() enabled = true end wait(2) --debounce wait d=true --reset debounce end end mouse.keyDown:connect(key) mouse.Button1Down:connect(punch)
Also you should learn UserInputService