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