So I am trying to make a GUI but I want all of the contents (text labels) to not be multiline. So I want a way to adjust the size of the text label on the X axis so that it fits all of the text in on one line, the problem is though that I want to do it from a script, because I have no way of telling which text labels will be created during the game itself, is there a way to do this?
Are trying to ask if there’s a way to check if a new Textlabel
is added to a gui? If that’s what you’re looking for then you’ll want to use Gui.ChildAdded
You know when you have text in a text label/button/box it automatically adds in multiple lines if the text is to long for the size of the X axis? I am trying to scale the X axis to the point where all the text fits on one line but I need it to be done from a script because I don’t know how long the text is.
If that makes sense.
Oh I get what you mean now. You’ll want to use a script that uses a for i loop that checks if the text fits while resizing it and not using textwraped. I’ll give an example of what I mean.
local TextObject = script.Parent--script should be inside the text gui object.
TextObject.TextWrapped = false
for I = 1, Enum.FontSize.Size96 do
TextObject.FontSize = I
if TextObject.TextFits then
break
end
end
Thanks so much for your help, so is Size96 the text size?
Size96 is a value of a FontSize Enum. The text size is changed by the FontSize
property of the TextObject
. The for loop goes threw all the FontSize
Enums and checks if the current FontSize
that has been set makes the text fit to the size of the TextObject
. If it does then it breaks the loop and the loop ends finishing the scripts thread.
Ah okay I get it now, thanks again for your help.