Help I tried making a combo system. But I don’t know why it starts with 2 on the first click, and it won’t properly reset the combo variable. Maybe I’m just ass at coding
local ComboV = 0
local maxCombo = 4
local lastM1Tick = 0
local resetTime = 1
local RS = game:GetService("RunService")
local function combo()
local Tick = RS.Stepped:Wait()
if Tick - lastM1Tick < resetTime then
if ComboV < maxCombo then
ComboV += 1
print(ComboV)
else
ComboV = 1
print(ComboV)
end
else
ComboV = 1
end
lastM1Tick = Tick
end
tool.Activated:Connect(function()
combo()
end)
your lastM1Tick is set to 0, this means tick-lastm1tick is beyond the reset time, and so when you click for the first time it resets your combo and doesn’t print the 1, it still works though. add a print statement when you reset the combo and you will see
Cz im on mobile it took time to re-arrange stuff but here:
local Debounce = false
local ComboV = 0
local maxCombo = 4
local resetTime = 1
tool.Activated:Connect(function()
if Debounce then return end
Debounce = true
if ComboV == maxCombo then ComboV = 0 end
ComboV += 1
print("Current combo: ", ComboV)
task.wait(resetTime)
Debounce = false
end)
I rewrote it and added comments, I suggest writing things like this in the future if you dont want to use OOP, if you have any questions on why I did it like this just let me know
local RS = game:GetService("RunService")
local MAX_COMBO = 4
local M1_COOLDOWN = 0.1
local M1_RESET_TIME = 1
local lastM1Time = 0
local comboCount = 0
local function Combo()
local currentTime = RS.Stepped:Wait()
local timeElapsed = currentTime - lastM1Time
if timeElapsed < M1_COOLDOWN then -- if they try to punch before the cooldown is up do nothing
return
end
lastM1Time = currentTime
if timeElapsed > M1_RESET_TIME then -- if its been long enough since the last punch, reset the combo
comboCount = 0
end
comboCount = (comboCount % MAX_COMBO) + 1 --increases the combo count by 1 and also makes sure it doesnt go over the max combo
print(comboCount)
end
tool.Activated:Connect(function()
Combo()
end)
I don’t think debounce would make any difference since op is already doing the tick refresh method. Unless the function takes longer than the ResetTime I don’t think this is necessary.