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

Can someone, in detail, explain to me how UDim2 works?

Asked by
Peeshavee 226 Moderation Voter
8 years ago

I checked wiki already, but I'm not understanding exactly what they mean. What confuses me is, if UDim2 controls a 2D surfaces, and Vector3 controls positioning of a 3D object, then why does UDim2 require 4 variables (1,2,3,4) and Vector3 only uses 3?(1,2,3). If someone could give me a detailed explanation, that'd be great!

2 answers

Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

A UDim2 value is a combination of two UDims, with an x axis and y axis. UDim stands for Universal Dimension, and it is used to position GUIs. UDims have two values, scale and offset.

The first two values in the 4 values are the scale and offset for the X axis, and the other two are the scale and offset for the Y axis.

What a scale is is the percentage of the space an object takes up. Say we had a Frame that covers the entirety of the screen. If the scale for the frame on the x axis was 0.5, the Frame would take up 0.5% percent of the screen on the x axis. Scale is ideal for sizing/positioning GUI objects so that they fit the screen.

An offset uses pixels rather than percentages. Let's say we wanted a Frame that was 30 pixels by 60 pixels. Inputting UDim2.new(0, 30, 0, 60) would convert to 30 pixels on the x axis and 60 on the y axis.

Ad
Log in to vote
0
Answered by 8 years ago

Here is how UDim2 works: (0,0,0,0) The first 2 are X coordinates, the first one is scale (1 = the size of its parent, 0.5 = half the size, etc.), the second one is offset, which is pixels. The last 2 are Y coordinates, they also have scale and offset

So if you do (0.5,0,0.5,0) the top left corner will be at the center of the screen, when you resize your screen, it will move accordingly. If you do (0,100,0,100), the top left corner will be 100 pixels (x and y) away from the corner of the screen, etc.

When you are using it in the properties, X and Y are seperated like this {0,0},{0,0} so keep that in mind.

Answer this question