TextLabel size not being changed, though childAdded event is working

I have a an auto-resizing text label based on the size of the text in the label. But for some reason, the event fires but the size does not change.

local Hints = script.Parent

Hints.ChildAdded:Connect(function(child)
if child:IsA("TextLabel") then
child.Size = UDim2.new(0, math.max(7, child.TextBounds.X) + 23, 0, 30)
print("oooh nice it works but nothing changes!!")
end
end)

If it auto resizes using the UISizeConstraint, then the size will be locked to the constraint and cannot be changed except through the constraint.

No, it is just a TextLabel with a UICorner inside.

1 Like

I know you’ve probably already tried this, but remove the

and just try a regular number, this will troubleshoot if this is the issue or something else.

Actually no I have not tried that, I will edit this when I get the result.

edit: definitely works!

1 Like

Ok now just remove the +23 and see if the math.max is giving you the max number.

Nope, still doesn’t work.

EDIT: wait It was giving the max number lol

1 Like

ok so then the +23 is the issue.

and you can workaround this by changing the math.max expression into a variable.

If that doesnt work, make the entire input there a variable so it doesnt have to do any math within the sizing.

1 Like

YEAHHHH, so it still doesn’t work. I’ve spend my entire evening just trying to fix this bug which does not display any errors or warnings.

is there any way I can utilize +=? im pretty sure there is not, but its worth a shot.

1 Like

What is your most recent script…

wdym ‘most recent script??’ The script that creates them?

No i mean the most recent edit of the script you first posted, with the math.max now made into a variable.

One sec let me show you what i mean…

1 Like
local Hints = script.Parent

Hints.ChildAdded:Connect(function(child)
local mathFix = math.max(7, child.TextBounds.X) + 23
if child:IsA("TextLabel") then
child.Size = UDim2.new(0, mathFix, 0, 30)
print("oooh nice it works but nothing changes!!")
end
end)

even tried removing the class checker but no difference.

local Hints = script.Parent

Hints.ChildAdded:Connect(function(child)
	if child:IsA("TextLabel") then
		local var = math.max(7, child.TextBounds.X)
		local newvar = var + 23
		child.Size = UDim2.new(0,  newvar, 0, 30)
		print("oooh nice it works but nothing changes!!")
	end
end)

This is a bit overkill but it might not let you do the math.max with additional math behind it.

I know but the thing is, I wanted to optimize the function, so instead of using this: while task.wait(0.1) do I decided to use an event to eat up less resources. And before then, it worked fine.

so honestly i really don’t know. i’ve tried everything i could think of.

1 Like

it shouldnt eat up much resource this way.

well the thing is, I was getting constant random lag spikes which is really bad for UX, since this thing is gonna be made public. And then I don’t want to put a script in each individual text label because that would be less efficient.

1 Like

I see… its your call. This last script should have worked though right?

no. it did not. sorry devforum for spamming msgs.

1 Like

Ok we’re closer than before! It’s not the +23 it’s actually the textbounds for some reason.