Debounce in my combat system script isnt working properly, if you spam m1 your character stop punching or dont punch at all.
local UIS = game:GetService("UserInputService")
local CombatHit = game.ReplicatedStorage.CombatHit
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Animator = Humanoid:FindFirstChildOfClass("Animator")
local Combo1 = Animator:LoadAnimation(script.Punch)
local InCombo = false
local Step = 0
local MaxStep = 3
local DB = false
UIS.InputBegan:Connect(function(Input,_gp)
if _gp then return end
if DB then return end
DB = true
if (Input.UserInputType == Enum.UserInputType.MouseButton1) then
if InCombo then
-- Continue combo
if Step ~= MaxStep then
Step += 1
Combo1:Play()
CombatHit:FireServer(Character, HRP, Humanoid)
else
InCombo = false
Step = 0
end
else
-- Start Combo
InCombo = true
Step = 1
Combo1:Play()
CombatHit:FireServer(Character, HRP, Humanoid)
end
print(DB)
end
-- Cooldown between punches
task.delay(.15,function()
DB = false
end)
end)
just move the db changing into the if statement that checks if its the mouse, because it changed the db every time any input was registered
local UIS = game:GetService("UserInputService")
local CombatHit = game.ReplicatedStorage.CombatHit
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Animator = Humanoid:FindFirstChildOfClass("Animator")
local Combo1 = Animator:LoadAnimation(script.Punch)
local InCombo = false
local Step = 0
local MaxStep = 3
local DB = false
UIS.InputBegan:Connect(function(Input,_gp)
if _gp then return end
if (Input.UserInputType == Enum.UserInputType.MouseButton1) then
if DB then return end
DB = true
if InCombo then
-- Continue combo
if Step ~= MaxStep then
Step += 1
Combo1:Play()
CombatHit:FireServer(Character, HRP, Humanoid)
else
InCombo = false
Step = 0
end
else
-- Start Combo
InCombo = true
Step = 1
Combo1:Play()
CombatHit:FireServer(Character, HRP, Humanoid)
end
print(DB)
-- Cooldown between punches
task.wait(.15) --no reason to use task.delay
DB = false
end
end)