im currently working on a combo, so far the debounce isnt working right and the combo gets randomized with a broken debounce causing it
local player = game.Players.LocalPlayer
local activated = false
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local firstattackdone = false
local secondattackdone = false
local thirdattackdone = false
local swing1 = script.Swing1
local swing2 = script.Swing2
local swing3 = script.Swing3
local swing1t = humanoid:LoadAnimation(script.Swing1)
local swing2t = humanoid:LoadAnimation(script.Swing2)
local swing3t = humanoid:LoadAnimation(script.Swing3)
local db = false
local animation = script.Animation
local animtrack = humanoid:LoadAnimation(script.Animation)
animtrack.Priority = Enum.AnimationPriority.Action
script.Parent.Equipped:connect(function()
activated = true
if activated then
animtrack:play()
end
end)
script.Parent.Activated:Connect(function()
firstattackdone = true
if db == false then
if firstattackdone then
db = true
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
swing1t:Play()
end
wait(2.06)
secondattackdone = true
firstattackdone = false
db = false
end
end)
script.Parent.Activated:Connect(function()
if db == false then
if secondattackdone then
print("ok")
db = true
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
swing2t:Play()
end
wait(1.19)
secondattackdone = false
thirdattackdone = true
db = false
end
end)
script.Parent.Activated:Connect(function()
if db == false then
if thirdattackdone then
db = true
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
swing3t:Play()
end
wait(1.33)
firstattackdone = true
thirdattackdone = false
humanoid.WalkSpeed = 9
humanoid.JumpPower = 50
db = false
end
end)
You have connected multiple functions to the Activated event; you should refactor your code so that one and only one function is connected to Activated.
Furthermore, if you’re doing a combo system, you should try using a numeric counter rather than several bool values.
local tool = script.Parent
local attackCounter = 0
tool.Activated:Connect(function()
-- Ignore this activation if we're on debounce:
if db then return end
-- Check here if the streak was broken (e.g. too much time since last attack)
if streakIsOver() then -- Write this function yourself!
attackCounter = 0
end
-- Now check the attack counter:
if attackCounter == 0 then
-- Perform first attack...
attackCounter += 1
elseif attackCounter == 1 then
-- ... then second ...
attackCounter += 1
elseif attackCounter == 2 then
-- ... finally the third! Then, reset.
attackCounter = 0
else
end
end
local player = game.Players.LocalPlayer
local activated = false
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local swing1 = script.Swing1
local swing2 = script.Swing2
local swing3 = script.Swing3
local swing1t = humanoid:LoadAnimation(script.Swing1)
local swing2t = humanoid:LoadAnimation(script.Swing2)
local swing3t = humanoid:LoadAnimation(script.Swing3)
local combo = 0
local db = false
local animation = script.Animation
local animtrack = humanoid:LoadAnimation(script.Animation)
animtrack.Priority = Enum.AnimationPriority.Action
script.Parent.Equipped:connect(function()
activated = true
if activated then
animtrack:play()
end
end)
script.Parent.Activated:Connect(function()
if db == false then
db = true
toolLastUsed = tick()
combo += 1
if combo == 1 then
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
swing1t:Play()
task.wait(2.06)
db = false
return
elseif combo == 2 then
print("ok")
db = true
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
swing2t:Play()
task.wait(1.19)
db = false
return
elseif combo == 3 then
db = true
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
swing3t:Play()
task.wait(1.33)
humanoid.WalkSpeed = 9
humanoid.JumpPower = 50
db = false
return
else
--if fourth or more combo
end
task.wait(2)
db = false
end
end)
task.spawn(function()
while task.wait() do
if tick() - toolLastUsed >= 3 then --if 3 seconds have elapsed since the tool was last activated reset the combo
combo = 0 --you can probably find a better way to handle combo achieving like detecting player hits
end
end
end)
Looks like the previous page and I were on a similar page, I’ve implemented a primitive combo system which you can definitely improve upon.
That last bit of that code which resets the combo leaves a lot to be desired (spawning a tight, infinite loop is an antipattern). It’s probably better for OP to just record the time of the last swing if it was too long ago.
local lastSwing
-- ...
local COMBO_TIME = 3
local lastSwing = nil
tool.Activated:Connect(function ()
-- ...
-- One condition for the combo's resetting is time-based:
local now = workspace.DistributedGameTime
if lastSwing and now - lastSwing > COMBO_TIME then
combo = 0
end
lastSwing = now
-- ...
end)
I’m aware, I even mentioned in the post that it was primitive and you will likely want to handle combo achieving differently (player hits was the example I provided which seems to be how most combo systems work).