Local script:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local attackEvent = tool:WaitForChild("AttackEvent") -- RemoteEvent to server
local anims = {
tool:WaitForChild("Slash1"),
tool:WaitForChild("Slash2"),
tool:WaitForChild("Slash3"),
tool:WaitForChild("Slash4")
}
local currentAttack = 1
local isAttacking = false
local lastAttackTime = 0
local comboResetTime = 1.5
local shortCooldown = 0.1
local stopConnection
local track
tool.Activated:Connect(function()
local now = tick()
if now - lastAttackTime > comboResetTime then
print("Combo timed out — resetting to first slash")
currentAttack = 1
end
if isAttacking then return end
isAttacking = true
local anim = anims[currentAttack]
if not anim then
isAttacking = false
return
end
if track then
track:Stop()
if stopConnection then
stopConnection:Disconnect()
stopConnection = nil
end
end
track = animator:LoadAnimation(anim)
track:Play()
print("Playing slash", currentAttack)
attackEvent:FireServer(currentAttack)
stopConnection = track.Stopped:Connect(function()
print("Animation ended for slash", currentAttack)
lastAttackTime = tick()
currentAttack += 1
if currentAttack > #anims then
currentAttack = 1
wait(0.5)
end
task.delay(shortCooldown, function()
isAttacking = false
end)
if stopConnection then
stopConnection:Disconnect()
stopConnection = nil
end
end)
end)```