Jump script not working

I’m trying to implement a jump cooldown using this script:

SIGNALS["HUMANOID_STATE_CHANGE"] = PLAYER_HUMANOID.StateChanged:Connect(function(OLD_STATE, NEW_STATE)
	if NEW_STATE == Enum.HumanoidStateType.Jumping then
		if CAN_JUMP then
			CAN_JUMP = false
			PLAYER_HUMANOID:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
			print("Disabled!")
			
			task.wait(5)
			
			CAN_JUMP = true
			PLAYER_HUMANOID:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
		end
	end
end)

but whenever my character jumps, “Disabled!” gets printed but I’m still able to jump.

I added

print(PLAYER_HUMANOID:GetStateEnabled(Enum.HumanoidStateType.Jumping))

under the print statement, and it shows that jumping is disabled. I have no other scripts handling the player’s humanoid

Hi @kx4gc
Instead use


SIGNALS["HUMANOID_STATE_CHANGE"] = PLAYER_HUMANOID.StateChanged:Connect(function(OLD_STATE, NEW_STATE)
	if NEW_STATE == Enum.HumanoidStateType.Jumping then
		if CAN_JUMP then
			CAN_JUMP = false
			PLAYER_HUMANOID.JumpHeight = 0
			PLAYER_HUMANOID.JumpPower = 0
			print("Disabled!")

			task.wait(5)

			CAN_JUMP = true
			PLAYER_HUMANOID.JumpHeight = 7.2
			PLAYER_HUMANOID.JumpPower = 50
		end
	end
end)
1 Like

Thank you, using this worked

SIGNALS["JUMP_SIGNAL"] = PLAYER_HUMANOID:GetPropertyChangedSignal("Jump"):Connect(function()
	if CAN_JUMP then
		CAN_JUMP = false
		PLAYER_HUMANOID.JumpHeight = 0
		PLAYER_HUMANOID.JumpPower = 0
		PLAYER_HUMANOID.Jump = false
		
		task.wait(5)
		
		CAN_JUMP = true
		PLAYER_HUMANOID.JumpHeight = STARTER_PLAYER.CharacterJumpHeight
		PLAYER_HUMANOID.JumpPower = STARTER_PLAYER.CharacterJumpPower
	end
end)
1 Like

Instead of setting JumpHeight/JumpPower and “Jump = false”, you could use JumpRequest in UserInputService to block the jump using states.

That way you can just use a cooldown and set the State Enum to enabled/disabled depending on whether or not they are in cooldown

1 Like

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