I was trying to make a Frame grow by its size by 0.1 and it didnt work... I'm still kinda new to the UDim2 thing..
script.Parent.Frame.Size.UDim2 = UDim2 + (0.1, 0.1, 0.1)
UDim2 isn't a value, it's a constructor. Constructors are made using NameOfConstructor.new(arguments)
, so obviously this code will not work as expected. The proper way to do this would be:
(P.S. UDim2 is for 2 dimensional elements such as GUIs, so you dont need 3 numbers!)
script.Parent.Frame.Size = script.Parent.Frame.Size + UDim2.new(0, 0.1, 0, 0.1)
This code will cause the frame's X and Y size to increase by 0.1. 0.1 is 10% of a pixel though, so you should probably increase it to get a noticable effect. Lets take a look at this code more, shall we?
The arguments for a UDim2 is as follows:
UDim2.new(ScaleX, OffsetX, ScaleY, OffsetY)
Scale represents a percentage of the frame's parent's size, going from 0 to 1; Assuming it's parent is a ScreenGui, ScreenGuis have a ''Size'' exactly the same as the size of their player's screen. So, if I made a GUI with a size of UDim2.new(0.5, 0, 0.5, 0)
, it would be exactly half of the player's screen size.
Offset is a hard-set number that decides how many pixels the size is, regardless of screen size. So if I made a GUI with a size of UDim2.new(0, 20, 0, 20)
, it would be a 20x20 pixel box.
What it is: Well, in a nutshell, UDim2 is like the Vector2/3 of GUIs. It is used to position or size GUIs!
How To Use It: To Use UDim2, you would do something along the lines of this:
script.Parent.Parent.Frame.Size = UDim2.new(2, 0, 1, 0)
What is UDim2?
UDim2
is a constructor for GUI
s. It acts the GUIs size/position. You may have noticed that there are four different numbers for UDim2. This is because there are two different parts to sizing and positioning a GUI. For example:
local exampleudim2 = UDim2.new(1, 100, 1, 100)
So what parts do what?
Both one values are Scale values. These values scale the gui size/position to fit the current monitor. If the Scale values are both one, then the gui will either be filling the whole screen, or completely off the screen. This is because the Scale value works like Transparency
values. Both are percentages in decimal form.
What do the other numbers do?
The 100 values are Offset values.. These numbers will make it so that the GUI will always stay at that position or size. Lets say that one of the values are 200, and that takes up two inches of your screen. On any other screen, it will take up two inches. This is because this value is not relative to the size of the screen. The Offset values are useful for things you want to stay the same size no matter what.