Textbounds.Y Not working with scaling textlabel offset

I got a custom chat, But for some reason, The Y Offset of the textlabel, Is not being set by the label.TextBounds.Y

Script
local event = game.ReplicatedStorage.PublicChatEvent
event.OnServerEvent:Connect(function(plr, message)
	local label = script.Parent.PlaceHolder:Clone()
	local filteredmessage = game:GetService("TextService"):FilterStringAsync(message, plr.UserId):GetNonChatStringForUserAsync(plr.UserId)
	label.Visible=true
	label.Parent=script.Parent
	label.Text= "["..plr.DisplayName.."]: "..filteredmessage
	label.MaxVisibleGraphemes=1+#plr.DisplayName+3
	if plr.AccountAge<=99 and plr.UserId~=133840022 then
		label.Text="[NEW PLAYER]["..plr.DisplayName.."]: "..filteredmessage
		label.MaxVisibleGraphemes=13+#plr.DisplayName+3
	elseif plr.AccountAge>=100 and plr.AccountAge<199 and plr.UserId~=133840022  then
		label.TextColor3 = Color3.new(0.780392, 1, 0.733333)
	elseif plr.AccountAge>=200 and plr.AccountAge<299 and plr.UserId~=133840022  then
		label.TextColor3=Color3.new(0.580392, 0.588235, 1)
	elseif plr.AccountAge>=300 and plr.AccountAge<=364 and plr.UserId~=133840022  then
		label.TextColor3=Color3.new(1, 0.447059, 0.454902)
	elseif plr.AccountAge>365 and plr.UserId~=133840022 then
		label.TextColor3=BrickColor.new("Gold").Color
		label.Text="[VETERAN]["..plr.DisplayName.."]: "..filteredmessage
		label.MaxVisibleGraphemes=10+#plr.DisplayName+3
	elseif plr.UserId==133840022 then
		label.TextColor3=BrickColor.new("Gold").Color
		label.Text="[OWNER]["..plr.DisplayName.."]: "..message
		label.MaxVisibleGraphemes=8+#plr.DisplayName+3
	end
	label.Size=UDim2.fromOffset(label.TextBounds.X, label.TextBounds.Y)
	game:GetService("TweenService"):Create(label, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut),{MaxVisibleGraphemes=#label.Text}):Play()
end)

Any info on how to shorten this is appreciated aswell.
The main issue is with label.Size=UDim2.fromOffset(label.TextBounds.X, label.TextBounds.Y)

What it does:
image
What it’s supposed to do (scaled with explorer):
image

Does anyone mind helping? Because the issue i have is annoying.

Please, This is really infuriating for me. I need to be able to get this to work.

A reply since nobody is currently helping me with the issue i am having.

The reason that you can’t use TextBounds.Y is because Roblox only determines that if the UI (TextLabel) is big enough to contain the text. It’s really frustrating.

Is there some reason you’re unable to use AutomaticSize for this?

Let’s assume you can’t for a minute:

In the past, before AutomaticSize the way I would handle this case that you’re struggling with is to move the UI out of the screen (set the position really far away) and make it really tall. Then I would wait for one frame and then I would read the TextBounds property, after that I would resize the UI on the Y axis to whatever my TextBounds + optional padding and then I would reset the position of the UI back to where it belonged.

Here’s an example of what this looks like:

local function set_text_and_auto_size_height(ui, text)
	ui.Text = text;

	local original_position = ui.Position;
	local original_size = ui.Size;

	ui.Position = UDim2.fromScale(100, original_position.Y.Scale);
	ui.Size = ui.Size + UDim2.fromOffset(0, 10000);

	task.defer(function()
		local text_bounds = ui.TextBounds;
		ui.Position = original_position;
		ui.Size = UDim2.new(original_size.X.Scale, original_size.X.Offset, original_size.Y.Scale, text_bounds.Y);
	end);
end

I fixed the big issue by setting the X and Y Scale to 1, Then when it is cloned, The Y Offset is set to the Textbounds.Y and the Y Scale is set to 0

So this helped me. And is considered, A solution.

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