Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

UDim2,new has a weird bug? results aren't good?

Asked by 4 years ago
Edited 4 years ago

So,

i'm making a GUI, like other people do with UDim2 for the best scaling.

Guess what.

UDim2.new is screwed.

This is what my gui should look like https://gyazo.com/b9bb089f6b95d7bd4a9df4ca057675a5

this is what it looks like after i UDim2.new in-game https://gyazo.com/dd39eb5b0f6c36c3eda585384e257d69

this also happens when i DONT UDim2.new

Also, if i test it in studio, it's screwed too!

This is my script

script.Parent.Size = UDim2.new(1,0,1,0)
script.Parent.Position = UDim2.new(0,0,0,0)
wait()
print(script.Parent.Size)
print(script.Parent.Position)
wait()
script.Parent.Button.Size = UDim2.new(0, 229,0, 77)
script.Parent.Button.Position = UDim2.new(0.434, 0,0.633, 0)
wait()
script.Parent.BGMid.Size = UDim2.new(0, 1653,0, 450)
script.Parent.BGMid.Position = UDim2.new(0, 0,0.296, 0)
wait()
script.Parent.BGBot.Size = UDim2.new(0, 165,0, 287)
script.Parent.BGBot.Position = UDim2.new(0, 0,0.736, 0)
wait()
script.Parent.BGTop.Size = UDim2.new(0, 1653,0, 387)
script.Parent.BGTop.Position = UDim2.new(0, 0,-0.082, 0)
wait()
script.Parent.Free.Size = UDim2.new(0, 500,0, 450)
script.Parent.Free.Position = UDim2.new(0.35, 0,0.297, 0)
wait()
script.Parent.OnHold.Size = UDim2.new(0, 500,0, 450)
script.Parent.OnHold.Position = UDim2.new(0.35, 0,0.297, 0)

someone, help me before ikms...

2 answers

Log in to vote
1
Answered by 4 years ago

Use scales and anchor points.

Scale

UDim2 values go like: (ScaleX, OffsetX, ScaleY, OffsetY). Scale is ratio with the screen. What I mean by that is if the ScaleX is set to 1, it'll fit the entire screen on the X axis. If it was set to 0.5, it would cover half the screen on the X axis. Same applies to ScaleY

Why use Scale? Well lets talk about Offsets for a bit. Offset is in pixels. If I made OffsetX set to 100, it will always be 100 pixels on the X axis. As you jump from studio to in-game, your resolution increases meaning more pixels will be on your screen.

By using scale, it ratios with the screen. It will always be the same on every screen. So if you cover the screen using scales, you'll be it'll cover it on any resolution.

Anchor Points

Anchor Points is a Vector2Value that scales with the GuiObject. It is defaultly in the top left of the GuiObject.

Now if you were to change the position of the GuiObject to say like UDim2.new(0.5, 0, 0.5, 0), the GuiObject would move based on the AnchorPoint, which is top left.

By changing the AnchorPoint from 0, 0 to 0.5, 0.5, it'll put the AnchorPoint in the center of the frame and by setting the frame in the middle of the screen, we can be sure that it'll stay in the middle no matter what resolution.

Conclusion

Use scale if you want it to fit the same for multiple resolutions (you could also use UIConstraints) and change the AnchorPoint to center GuiObjects.

Ad
Log in to vote
0
Answered by 4 years ago

I had some issues using it today, it seemed like the ScaleX takes value from the Y length of its parent.

Answer this question