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

Algorithm for centering a GUI element?

I've been trying to figure something out with GUIs...

If you want to center a GUI element, you need to set the size to a certain number depending on the position, and vice versa. A couple sizes and positions I found:

If the Size is 0.5, then the Position must be 0.25 to center

If the Size is 0.75, then the Position must be 0.125 to center

If the Size is 0.25, then the Position must be 0.375 to center

One I'm trying to find is If the size is 0.444, then the Position must be ??? to center

I've been using all sorts of methods to see if I could find some kind of connection between the position and the size. Dividing the Size by the Position... Dividing the Position by the Size, subtracting the Position by the Size, vice versa, adding the position and size together.

I'm still trying to figure it out, but while I worked at it, I figured I'd ask for some help if possible. Unless one of you guys know it. It would be extremely helpful.

Attempts so far

theawesome624: (1 - Size)/2 = Position. Confirmed!

1 answer

✓ Accepted answer

Use this

(1 - Size) / 2

Tests just to clarify (1 - 0.75) / 2 = 0.125 (1 - 0.5) / 2 = 0.25 (1 - 0.25) / 2 = 0.375

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