Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I center a GUI?

Hi, I couldn't get my GUI to position to the center of the screen so that if there Window is minimised or maximised.

At the moment I have my GUI at the top of the screen, but I don't think it's positioned properly. My current GUI position is: {0.4, 0},{0, 0}.

2 answers

Use the Scale value in the Position property to position the GUI to the center of your screen. Then, for other players, that GUI will be in around the same spot. The reason you don't want to use offset is because offset will make the GUI in the exact same position for everyone. So people with smaller screens might see the GUI in a really weird place.

3 comments

0

How do I do that?

0
0

Thanks. Do you think {0.45, 0},{0, 0} would be the middle?

A GUI's position and size is represented using: (XScale, XOffset, YScale, YOffset)

If you want the GUI to be in the centre of the screen regardless of the screen size then you should use offsets.

If you had a Frame that had the size (0,500)(0,250), and you wanted that frame to be centred perfectly in the middle of a players screen, then you would have (0.5,-250)(0.5,-125) as the position of it.

You essentially half the offset value for each axis, make it a negative number and add 0.5 in the XScale and YScale values.

XScale and YScale both can change the appearance of a GUI depending on the size of the ROBLOX window on a player's client. You should only use XScale and YScale for size if you need a GUI to cover the whole player's screen. If you aren't, you should be using XOffset and YOffset which are basically pixels.

More examples of a centred GUI could be:

TextBox of size (0,50)(0,100), position would be (0.5,-25)(0.5,-50) ImageLabel of size (0,700)(0,300), position would be (0.5,-350)(0.5,-150)

Finally, always remember that a GUI's position and size is measured from the top left corner of any GUI element.

This discussion is preserved as it was. New answers, comments, and votes are closed.