Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I use the Mobile button?

I'm using this code but, instead of using the Mobile Button it creates a new Button to use, how can I use the Mobile Button? the one of the left that walks and the one of the right that jumps?

local CAS = game:GetService("ContextActionService")

function OnButtonPress()
	print('Input W')
end
local m = CAS:BindAction("OnButtonPress",OnButtonPress,true,Enum.KeyCode.W)

1 answer

✓ Accepted answer

In order to manipulate the built in ROBLOX mobile buttons, you need to find them in the player's guis. From there you can check for input and do what you need.

if Player.PlayerGui:FindFirstChild("TouchGui") then--Check if the player is mobile
	local JumpButton = Player.PlayerGui.TouchGui:WaitForChild("TouchControlFrame"):WaitForChild("JumpButton")
	JumpButton.InputBegan:Connect(function(inputobject)
		if inputobject.UserInputType == Enum.UserInputType.Touch then
			--Whatever you want to happen when the player touches the jump button
		end
	end)
	JumpButton.InputEnded:Connect(function(inputobject)
		if inputobject.UserInputType == Enum.UserInputType.Touch then	
			--Whatever you want to happen when the player stops touching the jump button
		end
	end)
end

This discussion is preserved as it was. New answers, comments, and votes are closed.