Trying to make text background size change depending on text length and size

I want to make it so the background of my TextLabel or something like a frame resizes to fit the text depending on how long the text is and how large the text is. I want this effect to be similar to when you type in a textbox and the background of it (If there is one) resizes with it. The reason I want the background to resize to the text is because I have a script that changes what the text says.

I can’t find anything about this, and I’m not sure what I’d do to make this happen. I made the category Art Design Support since this is related to GUI, but this could also use script(s). I just wasn’t sure which, so I put it under that category.

To better help visualize this, I’ll show an example of what I’d want this to look like.

I don’t want the text to resize at all either unless it’s by some script unrelated to this. I don’t know if this would be a simple fix using something like a constraint or something more complicated.

I can’t change the background size to a set amount whenever another script changes the text. This is because I have many scripts that change the content of the text quickly and repeatedly, and I’d have to figure out each set amount every time the text changed.

1 Like

you can set the AutomaticSize property to X and then set the x size to the minimum size (or just 0)

2 Likes

I set the AutomaticSize property to X and I changed the size to {0, 0},{0.1, 0}, but when the text gets too long the background stops scaling in size and the text gets smaller. I’m unsure if I did something incorrect or if there’s something else I need to do.

i think textscaled doesnt usually work for this so you could try using a script like this to scale the text instead of using textscaled:

local function u()
    script.Parent.TextSize = script.Parent.AbsoluteSize.Y
end

u()
script.Parent:GetPropertyChangedSignal("AbsoluteSize"):Connect(u)

put that as a localscript inside of the textlabel and set textscaled to false
also if you want the text to be slightly smaller you can change this line:

script.Parent.TextSize = script.Parent.AbsoluteSize.Y

to be this:

script.Parent.TextSize = script.Parent.AbsoluteSize.Y * 0.9 -- put a multiplier here, 0.9 = 90% size
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.