Help with mobile button/ContextActionService

I am trying to make a button that is only viewable on mobile, that way mobile players can activate a keybind event. I have tried ContextActionService, but the buttons are far to small for the player to hit. I want to know how to resize the context action buttons, or more preferably bind a custom GUI to the service. is there any way I can do this? (note, the GUI does not have to be binded to ContextActionService. it just has to only be visible on mobile, I can script the rest :wink:)

1 Like

You’re able to create a function that is both used by your own UI and ContextActionService.

As for making a UI visible on certain devices, such as mobile, here’s a quick reference to that.

local mobile = game:GetService("UserInputService").TouchEnabled and not KeyboardEnabled

if mobile then
   --show mobile ui
   -- not mobile

Mobile devices can have a keyboard connected to them via USB/Bluetooth etc.

the problem is that my custom UI shows on computers, and as @Forummer has said some mobile devices can be used for display and be hooked up to a keyboard and mouse.

If you have trouble setting the size/position of the CAS buttons you should check out this module, does all of that for you:

To make a custom mobile GUI you could do something like:

if not (UserInputService.KeyboardEnabled) or (UserInputService.GamepadEnabled) then --If player is on mobile

--Set up mobile gui

Action() --Call action you want the button to perform

1 Like

I think ContextActionUtility is just what I need! Thanks for showing me this, I will add it to my game and if it works I will mark as solution!

1 Like

hey, I have played around with ContextActionUtility a little and I keep getting the error Unable to cast value to function. I do not know if you can help, but if you can this is my script:

local ContextActionUtility = require(game.ReplicatedStorage.ContextActionUtility)

local function TestFunc(actionName, inputState, inputObject)

ContextActionUtility.BindAction("Ability", TestFunc, true, Enum.KeyCode.E)

It’s a colon not a dot

local RepStorage = game:GetService("ReplicatedStorage")
local ContextActionUtility = require(RepStorage:WaitForChild("ContextActionUtility"))

local function TestFunc(actionName, inputState, inputObject)

ContextActionUtility:BindAction("Ability", TestFunc, true, Enum.KeyCode.E)

thanks! I am used to using a dot in custom modules I make lol.