I am currently attempting to make a sword combo system for a game.
The sword combo works as such:
- Initial swing (will not repeat)
- Swing 1
- Swing 2 (clicking after in combo loops back to swing 1)
The player is also unable to move during this timeframe.
While the swing system does work, I want to make the combo reset after some time, as in after some time of not clicking, the sword combo sets itself to 0 without the player having to click.
I am using a tool.activated event for this, so it could be that as the combo only resets to 0 whenever I click to activate the tool.
Is there any way that I can set it up so that the combo can reset outside of the tool.activated event? (preferably without any extra modules)
local combo = 0
local cancelCombo = 1.5
local lastTick = 0
local atkTime = 1
local attackFolder = {
[1] = "rbxassetid://9720688361",
[2] = "rbxassetid://9720688801",
[3] = "rbxassetid://9720689085"
}
local function attack(count)
if count < 1 then return end
print(count)
local atkAnim = Instance.new("Animation")
atkAnim.AnimationId = attackFolder[count]
local animTrack = loadAnimation(atkAnim, Enum.AnimationPriority.Action, false)
atkAnim = animTrack.Length
end
tool.Activated:Connect(function()
hum.WalkSpeed = 0
hum.AutoRotate = false
if tick() - lastTick <= cancelCombo then
combo += 1
if combo >= 4 then
combo = 2
end
attack(combo)
else
combo = 0
print("Combo Cancelled")
end
lastTick = tick()
wait(atkTime)
hum.WalkSpeed = 7
hum.AutoRotate = false
end)