I want to make a combat system with m1 punch (x4). Which is when player is delaying clicks or wait. The animaton will be reset to the beginning
Script:
local replicatedstorage = game:GetService("ReplicatedStorage")
local Default = require(replicatedstorage.ModuleScript.DefaultSettings)
local runservice = game:GetService("RunService")
local userinputservice = game:GetService("UserInputService")
local mouse = game.Players.LocalPlayer:GetMouse()
local returncombo
local COMBO = 0
local COMBO_DURATION = 0
local RETURNCOMBO_START_COOLDOWN = 2
local LIGHTCOMBO_COOLDOWN = 0.5
local LIGHTCOMBO_LAST_COOLDOWN = 2
local HIT_COOLDOWN = 0.5
local full_combo = false
local hit = false
local hit_debounce = false
local returnHit_debounce = false
local already_hit = false
local holding = false
local debounce = false
local function clickOrHold()
if debounce then return end
if not debounce then
COMBO += 1
comboHit(COMBO)
walkSpeed(Default.speed - 4)
hit = true
debounce = true
hit_debounce = false
task.wait(HIT_COOLDOWN)
walkSpeed(Default.speed)
task.wait(COMBO_DURATION)
debounce = false
end
end
local function returnCombo()
task.wait(RETURNCOMBO_START_COOLDOWN)
if not full_combo and not hit_debounce then -- I'm still confuse with this one.
print("returns")
full_combo = false
COMBO = 0
end
hit = false
hit_debounce = false
end
local function returnComboThread()
returncombo = task.spawn(returnCombo)
end
function walkSpeed(speed)
script.Parent:WaitForChild("Humanoid").WalkSpeed = speed
end
function comboHit(i)
replicatedstorage.HitboxEvent:FireServer(i)
end
runservice.Heartbeat:Connect(function (deltaTime)
if COMBO == 0 then already_hit = false end
if COMBO == 1 or COMBO == 2 or COMBO == 3 then full_combo = false already_hit = true COMBO_DURATION = math.abs(LIGHTCOMBO_COOLDOWN - HIT_COOLDOWN) end
if COMBO == 4 then COMBO_DURATION = math.abs(LIGHTCOMBO_LAST_COOLDOWN - HIT_COOLDOWN) full_combo = true task.wait(1) COMBO = 0 end
if holding then
clickOrHold()
end
if not hit_debounce and hit then
hit_debounce = true
returnComboThread()
end
end)
userinputservice.InputBegan:Connect(function(input,gpe)
if gpe then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
holding = true
end
end)
userinputservice.InputEnded:Connect(function (input,gpe)
if gpe then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
holding = false
end
end)
The script works fine, but it only returns when there’s a rapid clicks. Not a stalling clicks. Can anyone help me with this?