How do I make a frame that resizes based on how long the text inside it is

Hey there everyone,

Currently I’m trying to make a CanvasGroup that resizes based off how long the textlabel inside it is, I’ve searched around the Forum but they didn’t work for me for some reason.
Here is my layout:
image,

I’ve tried implementing a code like this:

HoverInfoUI.Size = UDim2.fromScale(HoverInfoUITextLabel.TextBounds.X / workspace.CurrentCamera.ViewportSize.X, HoverInfoUI.Size.Y.Scale)

But for some reason it doesn’t work because everytime I rehover over something the CanvasGroup gets a little smaller, until it becomes so small you cant see it anymore.

Help would be greatly appreciated!

Listen to text changed through GetPropertyChangedSignal("Text") and every time the text changes run code that scales the X axis, or the Y axis, or both axis of the frame(depending on what you want to achieve), enough so that TextBox.TextFits becomes true. You can also use the TextBox.TextBounds property to do the maths in an optimal manner. Lastly if your textbox has richtext support you may want to use ContentText instead.