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
--Variable local ScreenGui = script.Parent.ScreenGui --Create a new Frame local Frame = Instance.new("Frame",ScreenGui) --Change the Properties of the new Frame Frame.AnchorPoint = Vector2.new(0.5,0.5) Frame.Position = UDim2.new(0.5,0,0.5,0) Frame.Size = UDim2.new(0.25,0,0.25,0) local function SetFrameSize () --You can also replace everything in the function is by Frame.SizeConstraint and here that what you prefer local Choice = math.random(1,2) if Choice == 1 then Frame.SizeConstraint = Enum.SizeConstraint.RelativeXX elseif Choice == 2 then Frame.SizeConstraint = Enum.SizeConstraint.RelativeYY end end SetFrameSize()
Here you can skip from line 10 to 15 and select only one of the two relatives and replace them like this:
--Variable local ScreenGui = script.Parent.ScreenGui --Create a new Frame local Frame = Instance.new("Frame",ScreenGui) --Change the Properties of the new Frame Frame.AnchorPoint = Vector2.new(0.5,0.5) Frame.Position = UDim2.new(0.5,0,0.5,0) Frame.Size = UDim2.new(0.25,0,0.25,0) local function SetFrameSize () Frame.SizeConstraint = Enum.SizeConstraint.RelativeXX -- (Here I changed the script)or Frame.SizeConstraint = Enum.SizeConstraint.RelativeYY end end 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)