:GetPropertyChangedSignal() causing script to stop working

Hello,
Currently I am in the process of writing a script that checks a TextLabel for the word ‘elevator’. The Text can change at certain times, so I am using :GetPropertyChangedSignal(). However, adding the Property Changed Signal causes the function to not work.

The script:

--Looking for word 'elevator'

local textLabel = game.Workspace.TestPart.SurfaceGui.TextLabel
local newWord = string.lower(textLabel.Text)

textLabel:GetPropertyChangedSignal("Text"):Connect(function()
	print("Property changed.")
	if string.find(newWord, "elevator") then
		print("Found in string")
	end
end)
1 Like

Well, how is the TextLabel changing? If it is on the server and the client is somehow changing it then that is why it won’t detect the change. Can you share exactly how the change is being made?

Here is a basic version of how it is changed on the last two lines (via a ServerScript):

--Looking for word 'elevator'

local textLabel = game.Workspace.TestPart.SurfaceGui.TextLabel
local newWord = string.lower(textLabel.Text)

textLabel:GetPropertyChangedSignal("Text"):Connect(function()
	print("Property changed.")
	if string.find(newWord, "elevator") then
		print("Found in string")
	end
end)

wait(10)
textLabel.Text = "elevator"

It also may be worth noting that it does print “Property changed” however not “Found in string”.

Well, if this is how it is changed, then all you really need to do is:

--Looking for word 'elevator'

local textLabel = game.Workspace.TestPart.SurfaceGui.TextLabel
local newWord = string.lower(textLabel.Text)

textLabel:GetPropertyChangedSignal("Text"):Connect(function()
	print("Property changed.")
	if textLabel.Text == "elevator" then
		print("Found in string")
	end
end)

wait(10)
textLabel.Text = "elevator"

My bad I worded it poorly in the example I wrote; the word ‘Elevator’ is part of a sentence where certain characters can change. E.g. (ElevatorShaft - 0 votes).

local textLabel = game.Workspace.TestPart.SurfaceGui.TextLabel
local newWord = string.lower(textLabel.Text)

textLabel:GetPropertyChangedSignal("Text"):Connect(function()
	print("Property changed.")
	if string.find(newWord, "elevator") then
		print("Found in string")
	end
end)

wait(10)
textLabel.Text = "elevatorshaft"

In your code you are only setting newWord at the beginning of the code.

You need to move it down to inside the function like the following…

local textLabel = game.Workspace.TestPart.SurfaceGui.TextLabel

textLabel:GetPropertyChangedSignal("Text"):Connect(function()
	print("Property changed.")
    local newWord = string.lower(textLabel.Text)
	if string.find(newWord, "elevator") then
		print("Found in string")
	end
end)

wait(10)
textLabel.Text = "elevatorshaft"

Because in your past code “newWord” was set to the previous value of textLabel not the changed one.

1 Like

This worked, thank you for your help!

1 Like