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

GUI not centering

Alright, so I have a screengui in startergui, then a frame, then an imagelabel.

The imagelabel is this size:

{0, 100}, {0, 100}

So the way I learn it, 1 - 0.1 = 0.9 0.9/2 = 0.45

So I should put the position at..

{0.45 0}, {0.45, 0}

To centre it. Right?

Well it's not working, and it is a bit to the left of the centre.

The frame is at 1, 0 1, 0

So that shouldn't be an issue.

Am I doing something wrong?

3 answers

✓ Accepted answer

If you want to center your gui on screen with the size {0, 100}, {0, 100}, you should use the following formula for position:

Simplified Forumula (Offset only)

{0.5, -(width / 2)}, {0.5, -(height / 2)}

General Formula (Both scale and offset)

{0.5 - (xScaleSize / 2), -(xOffsetSize / 2)}, {0.5 - (yScaleSize / 2), -(yOffsetSize / 2)}

In this case, it would be

{0.5, -50}, {0.5, -50}

2 comments

2

I've downvoted your answer, because while this is the simplified formula, you should also give the generalized formula (to incorporate scale AND offset), which is UDim2.new(0.5-xScaleSize/2, -xOffsetSize/2, 0.5-yScaleSize/2,-yOffsetSize/2). Edit it to receive my upvote.

1

Ohhhhh kill em

A better way is to do something like this:

local gui = script.Parent
local size = gui.AbsoluteSize
gui.Position = UDim2.new(0.5, -size.X/2, 0.5, -size.Y/2)

it perfectly centers the Gui, and it will always be centered on every screen.

What would the position be instead of scripting the position. I have a button which moves and I want to know the position, so that I can position it to what the script is saying.

1 comment

0

wait what

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