How to set UI position [x] pixels from bottom of screen

I’ve never really gotten into UI design through scripting, but I would like to since it is highly used, and more professional. How would I make a UI that is 25 pixels away from the bottom of the screen, and say, 25 pixels away from the right side of the screen.

You usually don’t want to offset by pixels due to different screen sizes, you should use scale instead. Roblox counts the top-left corner of the screen as x0 y0 so you would need to do something like

ui.Position = UDim2.new(0.95, 0, 0.95, 0) --scaleX, offsetX, scaleY, offfsetY

to place it in the bottom right corner, tweaking the 0.95s as needed. If you really want to use pixels the second and fourth parameter to UDim2.new is in pixels.

1 Like

You can set the anchor point of your GUI. If you set it to (1,1) then anchor point will be at the bottom right.

When you position it you would position the GUI at the bottom right,

Position = UDim2.new(1, -25, 1, -25)

with the -25 to offset the pixel amount that you want.

Using anchor point you can position stuff around corners and edges very easily

Also @Mixu_78 has a good point, but if you want to keep a constant edge distance it is probably better to use a pixel amount rather than a 0.95 scale. For wider screens (mobile phones mostly) that 0.95 is further from the edge than for a thinner screen, so it could look misplaced.

Pixel positions/sizes near the center of the screen is more of an issue.

1 Like