I spent a pretty long time with my limited experience and scripting knowledge trying to figure out what's wrong with my script. The goal is to make a 3-hit combo that's chained together when you press DownArrow quickly (in a spammy fashion), and after a few hours I FINALLY got the chain part working, but the bigger problem has been getting the combo to reset to the first attack if there's too large a pause between button-pressing. The closest I got to fixing this issue was adding the spawn() function to time the pauses and reset the hitcount, but the problem is that the timing for it is all over the place regardless of what I set the maxTime to. Whether it's set to 1 or 5 or 1000, if I press DownArrow it will usually immediately print "took too long", and only occasionally actually takes as long as the maxTime is set. So why is that the case?

--Bind DownArrow to begin combo/attack
local enabled = true
local hitcount = 0
local startTime = 0
local maxTime = 2

local function onDBPress()
	UserInputService.InputBegan:connect(function(DB)
		if DB.KeyCode == Enum.KeyCode.Down then
			wait()
		if not enabled then
			return
		end
		enabled = false
		spawn(function()
		repeat	
			RunService.Heartbeat:Wait()
				until (tick() - startTime) > maxTime
				print("took too long")
			startTime = tick()
			hitcount = 0
			return
		end)
		wait()
		hitcount = hitcount + 1
			if hitcount == 1 then
				Humanoid.WalkSpeed = 0
				local AttackAnim1 = Humanoid:LoadAnimation(script.Attack1)
				AttackAnim1:Play()
				wait()
				for i = 1, 3 do
					Character.HumanoidRootPart.CFrame = 					Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-1)
					wait(0.01)
				end
				wait(0.3)
				Humanoid.WalkSpeed = 20
				enabled = true
			elseif hitcount == 2 then
				Humanoid.WalkSpeed = 0
				local AttackAnim2 = Humanoid:LoadAnimation(script.Attack2)
				AttackAnim2:Play()
				for i = 1, 5 do
					Character.HumanoidRootPart.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-1)
					wait(0.01)
				end				
				wait(1)
			Humanoid.WalkSpeed = 20
			enabled = true
			hitcount = 0
		end
	end
end)