Sorry if this is a stupid question, but isn’t the center of a frame always going to be 0.5, 0.5 (in scale, not offset)? Or is it specifically for offsets? If so, then why do you need to add the position of the GUI object and not just use its size and divide that by 2? I’m a total roblox studio nobody, so sorry if I’m saying something incredibly dumb right now
If you’re trying to center a GUI object, it also might help to change its anchorpoint to (.5, .5), then change its position to {.5, 0}{.5, 0}. Again, I could be grossly misunderstanding this because I’m a studio nobody who started like 2 weeks ago lol
AbsolutePosition and AbsoluteSize represent the exact position and size in PIXELS.
The trap is that they’re always in integers, which makes sense - I mean, you can’t magically slice a pixel on your monitor in any way, right?
When you change the size and position of your GUIObjects, the absolute position and size are always rounded into integers. This is why getting a center of a GUIObject with your method isn’t always accurate.
I’m glad to see that it was as simple as that—I don’t know what I would do if I got it completely wrong, lol. Anyway, even though I told you how to center a GUI piece properly, I still feel like I should explain it properly so you can apply it in different situations. [Insert a wise and relevant proverb here]
AnchorPoints decides where the position property gets applied on the GUI Object you’re trying to move. So wherever the anchorPoint is on a GUI, Roblox treats THAT as the center, and when you move the position of an object or a part, wherever the anchorpoint will be at the exact position you moved the part to. It defaults to the top left corner of the part (0, 0), and you can move the anchorPoint around like you would a position on a scale-based coordinate plane (one being x and the other being y).
What UI design pros usually do to simplify position movements is change the position of the anchorPoint depending on where you want to move the part. If you’re moving the part to the top right corner of something, then the anchorPoint should also be on the top right corner. If you’re moving something to be on the center left of the screen, then you move the anchorPoint to the center left of the screen. And if you’re moving something to be on the center of the screen (like you’re trying to do here), then the anchorPoint should be on the center of the screen. Hope this helps you in your future Roblox endeavors