Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does TextBounds.X stay at 0?

This is supposed to put another GUI at the correct position, but this keeps on messing me up:

local name = "text"
userLabel = C:WaitForChild("user")
userLabel.Text = name
local q = 20 + userLabel.TextBounds.X
-- q returns at 20 when it should go to the text size + 20.

I've also tried to find out this issue in different ways.

local name = "text"
userLabel = C:WaitForChild("user")
userLabel.Text = name
while true do
	if userLabel.TextBounds.X ~= 0 then
		break;
	end
	print("Waiting for TextBounds..")
	wait();
end
local q = 20 + userLabel.TextBounds.X

But the number stays at 0 and it won't change. Help is much appreciated.

  • Fighter169mobile

1 answer

✓ Accepted answer

I had a similar issue where it did not update the TextBounds due to it not being on the players screen.

A new service has been added TextService which you can calculate the text bounds with the function GetTextSize.

Example:-

local textServ = GetService('TextService')

local userLabel = C:WaitForChild("user")
userLabel.Text = "text"

local textBounds = textServ :GetTextSize(
	userLabel.Text,
	userLabel.TextSize,
	userLabel.Font,
	userLabel.AbsoluteSize
)

local q = 20 + textBounds.X

I hope this helps.

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.