How to resize a TextButton to fit text?

I’m working on a Notification System for my game, and I’d like to resize the notification label to fit the text sent by the server, like so

Default Notification ;

3779f5427da1deca282bc594804be410

How I’d like it to look when resized to fit the text.

976dc785154738787e8e489d1e97e5a4

How would I go at achieving this? I’ve tried alot but I can’t seem to quite get around it
Server does :FireClient(Player, Message) If your wondering.

Thanks.

Personally, I use TextService with :GetTextSize, you could try looking there.

If I’m understanding it correctly, then you need to enable this.
image

1 Like

I want to resize the textbox, not the text itself,

Did you try using TextService? The one I suggested?

1 Like

Hope this is what you wanted put this in in TextBox

local TS = game:GetService("TextService")

local e = script.Parent

e.Changed:Connect(function()
	local a = TS:GetTextSize(e.Text,e.TextSize,e.Font,Vector2.new(200,300))
	e.Size = UDim2.new(0,a.X,0,a.Y)
end)
6 Likes

More documentation on this parameter is requested, please.

local text = "Hello Roblox"
local a1 = TS:GetTextSize("Hello Roblox", 8, Enum.Font.Legacy, Vector2.new(300,100))  -- 71,12
local a2 = TS:GetTextSize("Hello Roblox", 8, Enum.Font.Legacy, Vector2.new(260,122))  -- 71,12
local a3 = TS:GetTextSize("Hello Roblox", 8, Enum.Font.Legacy, Vector2.new(10,10))  -- 10,12
local a4 = TS:GetTextSize("Hello Roblox", 8, Enum.Font.Legacy, Vector2.new(0,0))  -- 71,12

The (0,0) input vector actually came from Vector2.new(e.AbsoluteSize), which, in hindsight I’d rather parameterise as (btn.AbsoluteSize.X, btn.AbsoluteSize.Y), but I can’t yet pretend to understand the significance of this final parameter.