How do i make the combo reset?

how would I make the combo reset if there hasn’t been a hit for a second.

here’s the script

local CAS = game:GetService("ContextActionService")

local Combat_Event = game.ReplicatedStorage.Combat_Event

local player = game.Players.LocalPlayer
local Character = player.Character
local humanoid = Character:WaitForChild("Humanoid")


local combo = 1
local last_hit = 0

local can_hit = true

local animations = {
	'rbxassetid://16054362647', 
	'rbxassetid://16054511462',
	'rbxassetid://16054664934',
}
print(#animations)
local function punch(action_name, input_state, input_type)
	if input_state == Enum.UserInputState.Begin and can_hit then
		Combat_Event:FireServer()
		can_hit = false

		local animation = Instance.new("Animation", Character)
		animation.AnimationId = animations[combo]
		animation:Destroy()

		local hit_track = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
		hit_track:Play()

		if combo == #animations then
			combo = 1
			humanoid.WalkSpeed = 3
			humanoid:SetAttribute("Stunned", true)
			wait(1)
			humanoid:SetAttribute("Stunned", false)
			humanoid.WalkSpeed = 16
			can_hit = true
		else
			combo += 1 
			humanoid:SetAttribute("Attacking", true)
			wait(0.5)
			humanoid:SetAttribute("Attacking", false)
			can_hit = true
		end
	end
end
1 Like

Consider my post on a newer query.

This script I am writing here creates a value which is set to os.clock() which updates every M1, essentially if it stays the same after a second the combo resets.

local CAS = game:GetService("ContextActionService")

local Combat_Event = game.ReplicatedStorage.Combat_Event

local player = game.Players.LocalPlayer
local Character = player.Character
local humanoid = Character:WaitForChild("Humanoid")


local combo = 1
local last_hit = 0
local lastM1 = os.clock()

local can_hit = true

local animations = {
	'rbxassetid://16054362647', 
	'rbxassetid://16054511462',
	'rbxassetid://16054664934',
}
print(#animations)
local function punch(action_name, input_state, input_type)
	if input_state == Enum.UserInputState.Begin and can_hit then
                 local currentTime = os.clock()
                lastM1 = currentTime
                task.delay(1,function()
                       if lastM1 == currentTime then
                             combo = 1
                       end
                end
		Combat_Event:FireServer()
		can_hit = false

		local animation = Instance.new("Animation", Character)
		animation.AnimationId = animations[combo]
		animation:Destroy()

		local hit_track = humanoid:WaitForChild("Animator"):LoadAnimation(animation)
		hit_track:Play()

		if combo == #animations then
			combo = 1
			humanoid.WalkSpeed = 3
			humanoid:SetAttribute("Stunned", true)
			wait(1)
			humanoid:SetAttribute("Stunned", false)
			humanoid.WalkSpeed = 16
			can_hit = true
		else
			combo += 1 
			humanoid:SetAttribute("Attacking", true)
			wait(0.5)
			humanoid:SetAttribute("Attacking", false)
			can_hit = true
		end
	end
end
2 Likes

much appreciated bro
char limit

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.