How do I detect that text in a TextLabel has changed?

Hi,
I’m making an airport departure board. There is one column that has scrolling text.
My script resizes the TextLabel until the text fits. Now I want to resize it again after I changed the text, which is my problem.
I can’t detect if my Text has changed.

I tried the following:

local text = script.Parent.TextLabel
text.Changed:Connect(function(property)
	if property == "Text" then
		print("yessss change")
		text.Size = UDim2.new(1,0,1,0)
		changedsize = false
	end
end)

text:GetPropertyChangedSignal("Text"):Connect(function()
    print("yessss change")
    text.Size = UDim2.new(1,0,1,0)
    changedsize = false
end)

What did I do wrong?

Thanks in Advance :slight_smile:

1 Like

You don’t need this, you already have a event that listens if the text changes.

text.Changed:Connect(function(property)
	if property == "Text" then
		print("yessss change")
		text.Size = UDim2.new(1,0,1,0)
		changedsize = false
	end
end)

2 questions: 1: does it print “yessss change”?
and what’s the parent? if it’s in a frame and it prints, then you should change the size of the parent, or use the offset instead of the scale to resize it outside it’s boundaries.

Did you change something in that script?
I mean I tried both of the options I listed. I’m very surprised that it works now. Thanks :slight_smile:

The print thing is for me to know that it worked (so I don’t have to go in the explorer and see if it re-sized it.
The parent is another TextLabel, the scrolling (and now change detection) works very well.

I didn’t, I just told you to not to use

text.Changed:Connect(function(property)
   if property == "Text" then
   	print("yessss change")
   	text.Size = UDim2.new(1,0,1,0)
   	changedsize = false
   end
end)

Instead, use:

text:GetPropertyChangedSignal("Text"):Connect(function()
    print("yessss change")
    text.Size = UDim2.new(1,0,1,0)
    changedsize = false
end)
10 Likes