Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I use the Mobile button?

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by 6 years ago

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
Ad

Answer this question