How to set gui position depending on what device you are using

So I want to make a script that changes the position of the gui depending if the player is on pc or mobile.

I want it to look like this on pc:

and this on mobile:

I tried to do it with a script but it doesn’t work.

local UIS = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

if UIS.TouchEnabled and not UIS.KeyboardEnabled and not UIS.MouseEnabled
	and not UIS.GamepadEnabled and not GuiService:IsTenFootInterface() then
	script.Parent.Position = UDim2.new(0.979, 0, 0.686, 0)
end

If anyone knows how to make the script work somehow or has another solution feel free to reply.
Thanks!

1 Like

Just use this plugin, [Plugin] AutoScale Lite for GUIs - Scale your UI. Instead of using a script.

1 Like

I’ve been using this one for a while for positioning and it works pretty well.

1 Like

you could just make the position y to offset and keep the x to scale

You should be detecting the player’s screen size and change the position of the UI depending on their screen size.

If you want GuiObjects to be sized the same respective to the dimensions of the screen for every device then you need to size GuiObjects using the scale components only, as offset is a pixel count which means that for larger devices (with greater screen resolutions) a pixel offset will have a less obvious impact as opposed to the same pixel offset used on smaller devices (with lesser screen resolutions), when you size/position GuiObjects according to scale they will as its name suggests scale according to the dimensions of the native device.

1 Like