PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

JumpRequest

The UserInputService JumpRequest event fires when there is a jump request from the client (i.e. when the client pressed the spacebar or jump GUI button on mobile).

This event fires whenever the user tries to make their Player/Character jump. Default behavior responds to a jump request by setting the player’s Humanoid/Jump property to true, which makes the player’s character jump.

The event can be used to track every time a player wants to jump. Instead of using it to make a player jump, this should be used to change default jump behavior - such as disabling jumping.

For example, the code below prints “Jump” every time the player sends a jump request.

local userInputService = game:GetService("UserInputService")

function jumpRequest()
    print("Jump!")
end

userInputService.JumpRequest:Connect(JumpRequest)

Since this event fires multiple times for a single jump request, using a debounce is suggested.

If you would like to connect keys or buttons to other actions, consider using events such as UserInputService/GetKeysPressed and UserInputService/InputBegan or the ContextActionService.

As this event only fires locally, it can only be used in a LocalScript.


Code Samples


Disable Jumping

This code sample disables jumping for the LocalPlayer by setting the Enum/HumanoidStateType|Enum.HumanoidStateType.Jumping state to false. Setting this state to false as soon as the user tries to jump cancels the jump.

In order for this example to work as expected, it should be placed in a LocalScript.

-- Services
local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")

-- Local player
local player = players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

-- Fires when the user tries to jump
local function Jump()
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end

userInputService.JumpRequest:Connect(Jump)