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)
The Gui isnt actually a Gui in StarterGui, it’s set using ContextActionService:BindAction() with the ‘CreateTouchButton’ property to true (I’m assuming)
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
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")