How would I go about scaling a frame based on text length?

I’m trying to create a custom chat system, I’ve done all the basic stuff now I’m working on the visuals and such.

I’m wondering how I would scale the ‘message’ frame to somewhat fit the message.
image
As you can see, it’s a little too big for a ‘hey’.

This is how I handle the chat system on the client-side.

game:GetService("ReplicatedStorage").ChatUpdate.OnClientEvent:connect(function(user,text,color,perm,R,G,B)
	local newMsg = script.Frame:Clone();
	newMsg.Hold.Player.Text = user 
	newMsg.Hold.Text.Text = text
	newMsg.Hold.Player.TextColor3 = Color3.fromRGB(R,G,B)
	newMsg.Hold.Badge.Image = 'http://www.roblox.com/asset/?id='..perm
	newMsg.Hold.Parent = script.Parent
end)

image

Let me know :)

Maybe you can wrap the text and scale it.

No, that’d make the text be larger than it needs to be, and not uniform.

Additionally, please do not post your topics on other user’s posts when they have nothing to do with each other.

Yeah sorry I just really need help. And also that is the only way I know of. Unless you make the text label size based on the size of the text. so you make it very small like 1 letter and enable text wrapped.

This might help:

1 Like

I tried it, doesn’t work for me I guess. Still stays the same size.

You could use TextLabel.TextBounds (see the code on that page, it does pretty much what you want).

You could also use TextService:GetTextSize to predict the text’s size and resize the label accordingly.

4 Likes

Tried the TextBounds thing, and I’m going to go ahead and assume it’s not supposed to do this.

https://gyazo.com/2cf216d270a92e26f051d952d20b2124

(Just tried it with the example script)

Yeah, that example script seems limited. I would just use the second link to figure out what the size could be, and then resize your textbox accordingly.

1 Like