How to disable jump button on all input platforms

How to disable jump button on mobile, gamepad, and keyboard

skip to the 2nd part (Disabling jump buttons) to view the code to fork

preamble/yapping

After searching for every possible combination of keywords on how to disable the jump button on all platforms, I mostly found unsolved posts, or patchy solutions

I personally use a heavily-sandboxed version of the PlayerModule, so this tutorial was written taking into account devs who use forked PlayerModules, and only makes changes to a grand total of 3 lines of code

In my case for writing this tutorial, I have a character system that:

  1. has certain states (attacking, stunned, dialog, etc) where the jump input is disabled
    1a. some states can be simultaneously active
  2. has a custom jump button press behavior (double-jump, etc)
    2a. therefore the mobile jump button cannot be hidden
  3. runs on a tight, single-threaded loop that will most certainly be bottlenecked/throttled by:
    3a. ContextActionService:UnbindAction("jumpAction")
    3b. Iterating through current states and manually setting Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
  4. uses a single function to handle all jump inputs
    4a. unforked player module uses ContextActionService for Keyboard/Gamepad, and some unknown method for Mobile devices; why this is the case is beyond my comprehension
    4b. ControlScript ContextActions are rebound every input change, which means CAS:Bind/UnbindAction("jumpAction") is irrelevant and calling it on every input change is inefficient and unnecessary given the performance tradeoff against replacing 3 lines of code

Disclaimer 1: This requires a fork of the Roblox PlayerModule
Disclaimer 2: This tutorial was written with only keyboard, mobile, and controller inputs being taken into consideration
Disclaimer 3: if Humanoid.Jump = true is used in your codebase, it should be changed to Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)

Disabling jump buttons

\PlayerModule\ControlModule\Gamepad.lua

disables gamepad jump input (Enum.KeyCode.ButtonA)

--- target function:  (line 88)
function Gamepad:BindContextActions()
	-- ...
end

--- target declaration: (line 95)
local handleJumpAction = function(actionName, inputState, inputObject)
	self.isJumping = false -- (inputState == Enum.UserInputState.Begin)
	return Enum.ContextActionResult.Sink
end

\PlayerModule\ControlModule\Keyboard.lua

disables keyboard jump input (Enum.KeyCode.Space)

--- target function: (line 83)
function Keyboard:BindContextActions()
	-- ...
end

--- target declaration: (line 113)
local handleJumpAction = function(actionName, inputState, inputObject)
	self.jumpRequested = false -- self.jumpEnabled and (inputState == Enum.UserInputState.Begin)
	self:UpdateJump()
	return Enum.ContextActionResult.Pass
end

\PlayerModule\ControlModule\TouchJump.lua

disables touchscreen jump input (PlayerGui.TouchGui.TouchControlFrame.JumpButton)

--- target function: (line 139)
function TouchJump:Create()
	-- ...
end

--- target declaration: (line 166)
self.jumpButton.InputBegan:connect(function(inputObject)
	--A touch that starts elsewhere on the screen will be sent to a frame's InputBegan event
	--if it moves over the frame. So we check that this is actually a new touch (inputObject.UserInputState ~= Enum.UserInputState.Begin)
	if touchObject or inputObject.UserInputType ~= Enum.UserInputType.Touch
		or inputObject.UserInputState ~= Enum.UserInputState.Begin then
		return
	end

	touchObject = inputObject
	self.jumpButton.ImageRectOffset = Vector2.new(146, 146)
	self.isJumping = false -- true
end)

Video:

me when i press the jump button but its been disabled

6 Likes

why not just set JumpPower/JumpHeight to 0

1 Like

it’s easier to directly disable the jump input in this case

Do you have this in a .rbxl file, with a toggle to disable and enable ? via a script call?

Im using this for my horror game, thanks!