Reliably Detecting when Jump-Button on any Device is pressed?

Hello,


Is there a way to reliably detect when a jump key on any device is pressed (like with inputBegan)?

  • Detection should not need to be debounced
  • Detection should work when the character is in the air
game:GetService("UserInputService").InputBegan:Connect(function(inputObject)
      -- check if inputObject triggers a jump?
end)

What I have tried so far:


I know that you can use JumpRequest, but it fires multiple times when one button is pressed. Since I need to recognise key presses that happen in a short period of time, debouncing makes it impossible to recognise them.

game:GetService("UserInputService").JumpRequest:Connect(function()
end)

Another way would be to check the Jump-Property on a humanoid, but that also triggers mutiple times per button press.

humanoid:GetPropertyChangedSignal("Jump"):Connect(function()
end)

There is also the option to use humanoid.Jumping, but that only works when the humanoid is on the ground, but in my case I also need to detect jump button presses in the air.

humanoid.Jumping:Connect(function(changed)
end)

Thank you :slight_smile:

2 Likes

Humanoid.StateChanged

Humanoid.StateChanged:Connect(function(old, new)
    -- contains the old and new StateType
	if new == Enum.HumanoidStateType.Jumping then -- if HumanoidState is Jumped
		print("Jumped"); -- fire jumped
	end
end)

Jumping fires when the player enters and leaves the state as mentioned in its description.
:GetPropertyChangedSignal("Jump") will change from true to false everytime you jump, firing 2 times for each change, hence “Get Property Change Signal”
StateChanged can be explicitly used to check if the new state they are in is the Jumping state. This State wont change until the Player is in Freefall or back on the ground, but because its searching for the jumping state, it wont fire for other states unless told to do so.

2 Likes

Thank you for the quick reply, it works perfectly when the character is grounded, but I sadly also need to be able to detect a jump input when he is in the air (falling).

1 Like

Enum.HumanoidStateType.Freefall
Though, its not perfect.

1 Like

This would trigger once the player is falling, not when a jump-button is pressed

1 Like

Humanoid:GetPropertyChangedSignal(“Jump”)

1 Like

Then underneath that

If jump == true then

1 Like

This sadly needs to be debounced (or it would trigger multiple times per button click - even with “if jump == true”), which makes it impossible to detect key presses that happen in a short period of time.

1 Like

Sorry I didn’t read the full post

1 Like

I already explained in my post, why this doesn’t work/isn’t optimal for me.

1 Like

Perhaps you could use this method when they’re on the ground then the property changed signal when they’re in the air?

1 Like

What about this?

local UserInputService = game:GetService("UserInputService")
local Player: Player = game.Players.LocalPlayer

-- KeyCode (Desktop, Console)
UserInputService.InputBegan:Connect(function(input, gameProccesedEvent)
	if not gameProccesedEvent and (input.KeyCode == Enum.KeyCode.Space or input.KeyCode == Enum.KeyCode.ButtonA or input.KeyCode == Enum.KeyCode.ButtonX) then
		-- Do something
	end
end)

-- Touch (Phone, Tablet)
if UserInputService.TouchEnabled then
	local JumpButton: ImageButton = Player.PlayerGui:WaitForChild("TouchGui"):WaitForChild("TouchControlFrame"):WaitForChild("JumpButton")
	
	JumpButton.MouseButton1Click:Connect(function()
		-- Do something
	end)
end
7 Likes

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