How to convert this jump connection to mobile friendly

Hi, I am working on a game and I need to make it mobile friendly.

My Problem is I can’t find a way to make this function to mobile. Here’s the script:

function OnJump(Input,Processed) 
	if Processed then return end
	if Input.KeyCode == Enum.KeyCode.Space then
		if tick() - LastSpacePressed <= TIME_DELAY then
			Wallrun() -- after second jump player wallruns.
		else
			LastSpacePressed = tick()
		end
	end
end

UserInputService.InputBegan:Connect(OnJump)

The purpose of this script is to detect the first jump then detect the second jump and if it detects the second jump, the player is able to wallrun.

You can use ContextActionService to give it mobile support:

I tried that but I can’t use contextactionservice because roblox doesn’t allow you to bind actions to the mobile jump button. I don’t want to create a wallrun button. I want it able to detect the jump button on mobile too.

I found two similar topics to this one that may help:

1st topic I already have seen and tried: I can’t use JumpRequest because it doesn’t work for this type of script. And my movement module overrides the JumpRequest connection so it wouldn’t even work for PC.

2nd topic: works but doesn’t look very optimal.

Final Script

if UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled and not UserInputService.MouseEnabled
	and not UserInputService.GamepadEnabled and not GuiService:IsTenFootInterface() then
	local JumpButton = Player.PlayerGui.TouchGui.TouchControlFrame.JumpButton
	-- mobile device
	JumpButton.Activated:Connect(function()
		if tick() - LastSpacePressed <= TIME_DELAY then
			Wallrun()
		else
			LastSpacePressed = tick()
		end
	end)
end



function OnJump(Input,Processed) 
	if Processed then return end
	if Input.KeyCode == Enum.KeyCode.Space then
		if tick() - LastSpacePressed <= TIME_DELAY then
			Wallrun()
		else
			LastSpacePressed = tick()
		end
	end
end
1 Like

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