How to script the Jump Button on Mobile

Hi all,

I’m having issues scripting the Jump button on Mobile devices.

I’ve tried the following:

elseif ui.TouchEnabled then
	ui.InputBegan:Connect(function(input, game_processed_event)
		if input.UserInputType == Enum.PlayerActions.CharacterJump then
			activate()
		end
	end)
	
	ui.InputEnded:Connect(function(input, game_processed_event)
		if input.UserInputType == Enum.PlayerActions.CharacterJump then
			deactivate()
		end
	end)

Unfortunately, the Enum doesn’t work on Mobile. Using a ScreenGUI as a button works fine, however a lot of players automatically press the Jump button expecting to use it so I need to figure out a way to script it.

1 Like

Commonly, you would actually use the ContextActionService to do the input that way, but that’s more complex than UserInputService in general. On the other hand, working with it on UserInputService seems limited on trying to port it for mobile controls.

I checked every enumeration I could get in UserInputService, it is so far limited and doesn’t have any reliable methods for such.

It seems I have made a breakthrough, there is this.
UserInputService.JumpRequest

Correct, there is JumpRequest, however that would only work for the activate function when I also need something to run deactivate as well.

I tried BindAction with the ContextActionService however afaik you cannot use it with the Jump button.

game.Players.LocalPlayer.Character.Humanoid.StateChanged:Connect(function(state))
    -- your code
end)
 -- i know theres a event for if a stage has been changed, i kinda forgot that, you can check the devforum
-- if the humanoid state is falling (or jump idk i forgot) then activate,
-- if the humanoid state is not that, deactivate

Interesting. Let me take a look and see if I can figure something out.

Unfortunately, the StateChanged event does not work as expected. The player can press the button, but cannot hold it.

	character.Humanoid.StateChanged:Connect(function(old_state, new_state)
		if new_state == Enum.HumanoidStateType.Jumping then
			activate() 
		
		elseif new_state == Enum.HumanoidStateType.Freefall then
			deactivate()
		end
	end)

The activate function is called when the Jump button is pressed, however nothing happens when it is held down.