I have a GUI that will contain usernames that I want to fit exactly around the username.
I was wondering if there was any way to do this other than
while not button.TextFits do button.Size = button.Size + UDim2.new(0, 1, 0, 0) end
You can use the TextService which contains the function GetTextSize that allows you to calculate the size of a frame needed for the inputted test along with its font and size.
A small example:-
local textServ = game:GetService('TextService') local button = [some path to the button] local newSize = textServ:GetTextSize(button.Text, button.TextSize, button.Font, button.AbsoluteSize) -- passes back a Vector2 -- set new button size button.Size = Udim2.new(0, newSize.X, 0, newSize.Y)
I hope this helps.