How to make ContextActionService mobile button fit on other devices?

I’m working on my game and it needs a sprint button for mobile, so I used ContextActionService, but what I want to do is make it so the GUI can fit on any mobile device. Is there any way to do this?

This is where I want to button to be on (IPhone 4)

I don’t want the button to be here (IPad Pro)
image

2 Likes

If your sprint button is inside of the startergui. Then you need to have a plugin called Gui Rescaler. Here it is.

After you downloaded it. Make sure to click on the Ui and then click on the Gui Rescaler Plugin In the plugins tab.

Hope this helped you!

Also make sure that you must select a device for it to work else It will stay on the position for every device.

1 Like

My Gui is from ContextActionService, will it work?

Yes. You can use it on any place. If its a screengui or if you use a sprint as a button. You can select that and then do the same thing.

How can I set the rescale on the sprint Gui, when it only appears when someone joins the game on mobile?

If you actually rescale. It sets all offsets and converts them into accurate scales.

What I’m trying to say is how can I do this on the Gui when the Gui only appears when someone joins the game on mobile?

What is the Position of the Gui?

The Gui isnt actually a Gui in StarterGui, it’s set using ContextActionService:BindAction() with the ‘CreateTouchButton’ property to true (I’m assuming)

This is taken out from the script
game:GetService("ContextActionService"):SetPosition('keyPressSpecialName',UDim2.new(0.25,-25,0.66,-25))

That’s exactly what I was trying to say.

You can set the position of it by using ContextActionService:SetPosition(actionName, pos) but I dont see one for Size.

ContextActionService:SetPosition (roblox.com)

1 Like

I already tried doing that, by using the plugin, and putting the new position in the script. But it didn’t work.

The position is right on mobile but not on IPad Pro?

Yeah I dont really see a way of doing this hmm.

I think its a better idea putting 2 Gui’s. But with different scales for mobile and ipad.

Seeing the replies, I think it’s best to make your own mobile buttons like the wiki says and you can use this piece of code to check what platform a player is on. Make sure to set the size using scale so it scales properly on phones and tablets, you can also use UIAspectRatioConstraint to keep the button as a square.

function GetPlatform()
	if GuiService:IsTenFootInterface() then
		return "Console"
	elseif UserInputService.TouchEnabled and not UserInputService.MouseEnabled then
		return "Mobile"
	else
		return "PC"
	end
end
2 Likes

I found the size and position of the jump button and mess with it (because I was frustrated to rescale these mobile buttons) Here’s an example:

local ContextActionService = game:GetService("ContextActionService")
local CurrentCamera = workspace.CurrentCamera

local MinAxis = math.min(CurrentCamera.ViewportSize.X, CurrentCamera.ViewportSize.Y)
local IsSmallScreen = MinAxis <= 500
local ActionButtonSize = IsSmallScreen and 70 or 120

local function RescaleActionButton(Name)
	local ActionButton = ContextActionService:GetButton(Name)
	
	if ActionButton then
		local ActionTitle = ActionButton:WaitForChild("ActionTitle")

		if not IsSmallScreen then
			ActionTitle.TextSize = 36
		else
			ActionTitle.TextSize = 18
		end

		ActionButton.Size = UDim2.fromOffset(ActionButtonSize, ActionButtonSize)
	end
end

local function HandleAction(ActionName, InputState, InputObject)
	if InputState == Enum.UserInputState.Begin then
		print("Interacting Something...")
	end
end

ContextActionService:BindAction("Interact", HandleAction, true, Enum.KeyCode.E)
ContextActionService:SetPosition("Interact", IsSmallScreen and UDim2.new(1, -(ActionButtonSize * 2.52 - 10), 1, -ActionButtonSize - 20) or
	UDim2.new(1, -(ActionButtonSize * 2.52 - 10), 1, -ActionButtonSize * 1.75))
ContextActionService:SetTitle("Interact", "Interact")
RescaleActionButton("Interact")
3 Likes