I want to make a perfect square frame (100 by 100, if possible) in the perfect middle of the screen. But when I use the Offset, it's 100 by 100 pixel on every device, so it's a perfect square everywhere, but 100 pixel on a phone is too big. When I use Scale, it's 100 pixel on my screen, but on an Xbox its 117 by 126. That's not a square. Same thing at position. Do someone know how to make a perfect ~100 by 100 in the perfect middle of the screen in each device?
You can use a UIAspectRatioConstraint to achieve this. You can insert it in a GuiObject.
Made 100% by @Eternalove_fan32
01 | --Variable |
02 | local ScreenGui = script.Parent.ScreenGui |
03 | --Create a new Frame |
04 | local Frame = Instance.new( "Frame" ,ScreenGui) |
05 | --Change the Properties of the new Frame |
06 | Frame.AnchorPoint = Vector 2. new( 0.5 , 0.5 ) |
07 | Frame.Position = UDim 2. new( 0.5 , 0 , 0.5 , 0 ) |
08 | Frame.Size = UDim 2. new( 0.25 , 0 , 0.25 , 0 ) |
09 | local function SetFrameSize () --You can also replace everything in the function is by Frame.SizeConstraint and here that what you prefer |
10 |
11 | local Choice = math.random( 1 , 2 ) |
12 | if Choice = = 1 then |
13 | Frame.SizeConstraint = Enum.SizeConstraint.RelativeXX |
14 | elseif Choice = = 2 then |
15 | Frame.SizeConstraint = Enum.SizeConstraint.RelativeYY |
16 | end |
17 | end |
18 | SetFrameSize() |
Here you can skip from line 10 to 15 and select only one of the two relatives and replace them like this:
01 | --Variable |
02 | local ScreenGui = script.Parent.ScreenGui |
03 | --Create a new Frame |
04 | local Frame = Instance.new( "Frame" ,ScreenGui) |
05 | --Change the Properties of the new Frame |
06 | Frame.AnchorPoint = Vector 2. new( 0.5 , 0.5 ) |
07 | Frame.Position = UDim 2. new( 0.5 , 0 , 0.5 , 0 ) |
08 | Frame.Size = UDim 2. new( 0.25 , 0 , 0.25 , 0 ) |
09 | local function SetFrameSize () |
10 |
11 | Frame.SizeConstraint = Enum.SizeConstraint.RelativeXX -- (Here I changed the script)or Frame.SizeConstraint = Enum.SizeConstraint.RelativeYY |
12 |
13 | end |
14 | end |
15 | SetFrameSize() |
You have to copy the code and put it in the StarterGui without anything else. I hope this has helped you ^-^ (Your @Eternalove_fan32)