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

How to scale GUI's instead of using pixel counts?

I’m unsure how I would use scalars to reposition my GUI depending on the value of a changing leaderstat.
Since the value can increase from 0 and go well into the millions, I don’t know how I can keep the text’s position scaled correctly.

local textBox = script.Parent

local minWidth, minHeight = 50, 50 -- This line needs changing

textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextYAlignment = Enum.TextYAlignment.Top

local function updateSize()

textBox.Size = UDim2.new(
0, math.max(minWidth, textBox.TextBounds.X),
0, math.max(minHeight, textBox.TextBounds.Y)
)
end
textBox:GetPropertyChangedSignal("TextBounds"):Connect(updateSize)

Thanks for the help!

1 comment

0

Can you edit your question to fix that last line?

1 answer

You just put the numbers in the Scale parameters like UDim2.new(0.5, 0, 0.5, 0) and the numbers represent UDim2.new(xScale, xOffset, yScale, yOffset). In your case, if you want it to be in the top right where the default leaderboard is, you would do UDim2.new(1 - TextBox.Position.X.Scale, -TextBox.Position.X.Offset, 0, 0). The reason I subtracted the X size from the position is because if not, it'll be off the screen.

1 comment

0

So where I have - local minWidth, minHeight = 50, 50 - I change the 50, 50 part to something like (0.5, 0, 0.5, 0)?

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