No jumping while m1'ing | Combat System

I want players to be unable to jump and to move more slowly while performing M1 (punching) action, regardless of whether they’re just clicking or holding down the button.

The problem is preventing jumps and keeping reduced movement speed during M1s whether in a chain or not without only relying on the mouse. I tried disable jumping and slow the walk speed for each m1 animation, but players could still jump between punches when chaining or holding down M1. So I need a way to detect if another M1 will immediately follow the current one so that the jump stays prevented and reduced movement speed stays while chaining.

here’s my script:

local lastClicked = 0

local function resetNoPunchTwoSeconds()
	task.spawn(function() -- if 2 seconds passed then punch combo resets
		while true do
			task.wait(0.1)
			if tick() - lastClicked >= 2 and not mousePressed then
				currentPunchPosition = 1
			end
		end
	end)
end

local function executePunchSequence(isPunchHold) -- if this is true then its an m1 chain
	if currentPunchPosition >= maxCombo then
		currentPunchPosition = 1
		return
	end

	humanoid.WalkSpeed = 8
	humanoid.JumpPower = 0
	humanoid.JumpHeight = 0


	-- Set up hitbox
	task.spawn(function()
		hitboxSet()
		hitboxDeploy()
	end)

	-- Handle hit detection (unnecessary to read)
	task.spawn(function()
		hitDetection(function(hitPlayers)
			for enemyCharacter, _ in hitPlayers do
				hitPlayer = true

				enemyPlayer = Players:GetPlayerFromCharacter(enemyCharacter)
				enemyTorso = enemyCharacter:WaitForChild("Torso")
				enemyHumanoid = enemyCharacter:WaitForChild("Humanoid")
				enemyCharacterHead = enemyCharacter:WaitForChild("Head")

				characterHead = character:WaitForChild("Head")

				local direction = torso.CFrame.LookVector
				local differenceDirection = (enemyTorso.Position - torso.Position).Unit
				-- Set up continuous dot product updating
				if runConnection then
					runConnection:Disconnect()
				end
				runConnection = RunService.RenderStepped:Connect(function()
					updateDotProduct(characterHead, enemyCharacterHead)
				end)

				-- Handle blocking
				if handleBlocking(enemyCharacter) then
					blockSound:Play() -- ensure that this works
					return -- Stop further logic if blocking
				else

					-- Set up animation markers
					if enemyTorso and differenceDirection then
						table.insert(markerConnections, currentTrack:GetMarkerReachedSignal("prepunch"):Connect(function()
							print("prepunch is reached.")
							hitPush(torso, differenceDirection)

						end)

					end
				end
			end
		end)
	end)

	-- After the animation
	currentTrack.Stopped:wait()

	humanoid.WalkSpeed = originalWalkSpeed
	humanoid.JumpPower = originalJumpPower
	humanoid.JumpHeight = originalJumpHeight

	currentPunchPosition += 1
end

local function mouseButtonHold(actionName, inputState, inputDetails)
	if inputState == Enum.UserInputState.Begin then
		mousePressed = true
		timePressed = tick()

		-- Execute immediate punch when mouse is first pressed
		if not isPlayingClick and not isPlayingHold and humanoid then
			if character:GetAttribute("Stunned") then return end

			--lastHumanoidSpeed = humanoid.WalkSpeed
			isPlayingClick = true


			resetNoPunchTwoSeconds()
			resetNoHitTwoSeconds()
			lastClicked = tick()

			executePunchSequence(false) -- Normal punch sequence

			isPlayingClick = false

		end

	elseif inputState == Enum.UserInputState.End then
		mousePressed = false

	end
end

ContextActionService:BindAction("normalPunch", mouseButtonHold, true, Enum.UserInputType.MouseButton1)

-- Handle continuous punching while held
task.spawn(function()
	while true do
		task.wait(0.08)
		if mousePressed and not isPlayingHold and not isPlayingClick then
			local currentPressDuration = tick() - timePressed
			if currentPressDuration >= 0.01 then
				if character:GetAttribute("Stunned") then return end
				isPlayingHold = true


				resetNoPunchTwoSeconds()
				resetNoHitTwoSeconds()

				executePunchSequence(true) -- Hold punch sequence

				isPlayingHold = false
			end
		end
	end
end)

any help is appreciated

2 Likes

IDK why your script is not working but after currentTrack.Stopped:wait() try:

task.wait(endLag)

if isAttacking then return end

-- Reset the walking and jumping back to normal here..

Also, is this in a local script? Setting the walkspeed and jumpspeed for a player in a server script is never good, and the blocking and that stuff should be handled by server for anticheat purposes.

2 Likes

Unfortunately this isn’t the solution that i need.

i don’t want to stop the script after endlag when each animation ends, i wanna instead be able to detect if there would be another m1 incoming when doing an m1, so i can keep the jump and speed the same.

1 Like

Like, from a different player? The script i sent would be to, after a bit of a second, check if the player is m1-ing again (Detect if another m1 is incoming) and if not then return the walk speed and jump height.

Does your combat system allow multiple m1s at once? If so, I think you can prompt them in an array for each m1 and remove one after completion to detect if any new ones are incoming, and continue from there.

2 Likes

can you explain what isAttacking variable is and how it would detect if another m1 is incoming?

1 Like

In this case, the simplest solution I can think of is letting the small stun left for some miliseconds even after the animation ends.

1 Like