Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How does UDim2 work, and why do my boxes keep going off screen?

Im extremely confused with the functionality of UDim2. I thought it would be simple: Set X and Y coordinates, and you're done. However, I have the following code:

Statbox = script.Parent.StatBox
Quirkbox = script.Parent.StatBox
Skillbox = script.Parent.SkillBox
Skillbox.Position = UDim2.new(100,300)
Quirkbox.Position = UDim2.new(100,200)
Statbox.Position = UDim2.new(100,100)

This places a single box half-on screen and the others way off screen. I tried setting them all to the same position: The two other boxes were still off screen. I just need guidance, I have absolutely no clue how UDim2 works.

2 comments

0

I've tried the UDim2.new(X,XOffset,Y,YOffset) version of UDim2, but I have no clue how XOffset and YOffset work either. I'm trying to make the game resize my GUI to the user's screen size.

0

UDim2.new(0,0,0,0) for example.

1 answer

✓ Accepted answer

quickfix:

Statbox = script.Parent.StatBox
Quirkbox = script.Parent.StatBox
Skillbox = script.Parent.SkillBox
Skillbox.Position = UDim2.new(0,100,0,300)
Quirkbox.Position = UDim2.new(0,100,0,200)
Statbox.Position = UDim2.new(0,100,0,100)

If you don't understand the (0,0,0,0) and each part does I will explain:
So first it is (X Scale, X Offset, Y Scale, Y offset)
X and Y scale is do to with screen percentages, (0,0,0,0) is the left top corner, (1,0,1,0) is the right top corner, (0.5,0,0.5,0) is the center of the screen (if AnchorPoint is 0.5,0.5), this means that whatever number you put in, the position will be the same on every screen.
X and Y offset is set by pixel eg (0,200,0,200) will be 200 pixels right and 200 pixels down, the positioning will not be the same on every screen.

2 comments

0

Thanks, dude! Hopefully I can use UDim2 to resize based on the user's interface.

0

Also, I just realized why Quirkbox wasn't scaling; I declared Quirkbox = script.Parent.StatBox. It's meant to be Quirkbox = script.Parent.QuirkBox

This discussion is preserved as it was. New answers, comments, and votes are closed.