Positioning ContextActionService mobile buttons

This is pretty simple and self explanatory, im trying to position mobile buttons yet they dont seem to go to the right position even though everything is using scale instead of offset

Supposed position:

What I Get:
image

code to position them:

-- custom button position
ContextActionService:SetPosition("Punch", UDim2.new(0.93, 0,0.353, 0))
ContextActionService:SetPosition("Kick", UDim2.new(0.93, 0,0.471, 0))
ContextActionService:SetPosition("Block", UDim2.new(0.93, 0,0.589, 0))
ContextActionService:SetPosition("Stance", UDim2.new(0.93, 0,0.103, 0))

This is actually due to the case where the Mobile Button’s Positions for ContextActionService are strictly chained as an automatic Frame is attached to every action that’s currently binded, and have their createTouchButton parameter set to true

(Button’s Position is UDim2.new(0, 0, 0, 0))

A way to workaround this, is by retrieving the Mobile Button by calling in the GetButton method, which returns back as a ImageButton Instance where you can set the .Parent property to your own Button UI, but just keep in mind that you’ll have to mess around with their .Size & .Position properties to get the desired result that you want

local CAS = game:GetService("ContextActionService")
local Plr = game.Players.LocalPlayer
local PlrGui = Plr:WaitForChild("PlayerGui")
local OtherUI = PlrGui:WaitForChild("MobileButtons")

local function TestFunction()
	print("Yes")
end

CAS:BindAction("Test", TestFunction, true)

local Button = CAS:GetButton("Test")
Button.Parent = OtherUI.Frame

1 Like

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