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

(Easy) How would you center a any surface gui so it is exactly in the center of a block?

I am working on an fps and for the attachment to work, I need to have a way where the surface GUI is exactly in the center of my scope part so that it perfectly fits with the mouse. The problem I have is that I am pretty much terrible with UI and GUI overall, so I have no clue how to do so. I'm hoping that this is possible or there is some way to know what the offset has to be depending on the size of the image. Thanks!

2 comments

0

Wrong site, buddy.

0

Nope

1 answer

✓ Accepted answer

The SurfaceGui itself has no visuals, it just provides you with a container to put UI elements in, and some control over the overall pixel resolution. You can easily center things by adding a Frame child to the SurfaceGui with Size of (1,0,1,0) (that's UDim2.new(1,0,1,0) in code) and Position of all zeros. This frame fills the SurfaceGui, and can be set transparent. Then, anything you want centered, you just make it a child of the Frame and set AnchorPoint to (0.5, 0.5) and Position to (0.5, 0, 0.5, 0) That's 0.5 for the Scale values, and 0 for the pixel offsets.

2 comments

0

Thank you!

0

Thank you!

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