Only jump when the jump button starts being held down

pretty self-explanatory. many games like phanton forces and others have a system where you can only jump when you begin to press the jump button, not when you hold it down. im looking for an answer that relies on UserInputService.JumpRequest and not on InputBegan

1 Like

This solution does use InputEnded, but I cannot think of another solution as you have to detect at some point if the player has let go of space.

This is a local script in StarterCharacterScripts


local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local Player = Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

local CanJump = true

Humanoid.Jump = false
Humanoid.JumpHeight = 0

local function OnJumpRequest()
	if CanJump then
		CanJump = false
		Humanoid.JumpHeight = 7.2 -- Default jump height
		Humanoid.Jump = true
		
		task.wait(0.1)
		
		Humanoid.JumpHeight = 0
	end
end

UserInputService.InputEnded:Connect(function(Input, GameProcessed)
	if Input.UserInputType == Enum.UserInputType.Keyboard and not GameProcessed then
		if Input.KeyCode == Enum.KeyCode.Space then
			CanJump = true
		end
	end
end)

UserInputService.JumpRequest:Connect(OnJumpRequest)

is there like a specific space in time between frames where JumpRequest hasnt been checked yet?

I’m not very sure what you mean. But JumpRequest is fired many times per second when the player tries to press and hold jump.

when the jump button is held down, jumprequest is fired every frame. when does it fire every frame

Sorry, I’m not very sure about that. Are you looking for a solution that doesn’t use InputEnded as well?

well i could just use inputbegan and inputended its not that urgent but there’s never been a solution to this problem yet

Hey! I initially saw you ask this question in another thread, and after a couple hours of research and experimenting in Roblox Studio, I ended up finding a solution that does work for multiple UserInputTypes.

I ended up posting my response to your question in that thread since that’s where I saw it first and it also happens to more accurately address the original question of that thread in comparison to the previous solutions that were offered.

  • (For example, Humanoid.JumpPower was used in some of the alternative solutions, however, the official documentation for that property on the Roblox Creator Documentation site mentions that it’s recommended to use Humanoid:SetStateEnabled(), for that use case, instead.)