:GetPropertyChangedValue not firing for updated values, only for the first ever value of a variable

I am trying to make a plugin which shows the part’s size on a TextLabel.Text property. However it doesn’t detect the change in scale when scaled using the scale tool. Only updates the value whenever I select out of it, and select it again.


:GetPropertyChangedSignal doesn’t fire for updated objects defined in a variable.

It only fires for the object I used to initialise the variable. No matter how many times I defined the variable.

Here is the code:

local currentlySelect = workspace['PLUGINPart_DoNotRemove_1a2b3c4de5f6']

local function getObject(gui)
 local obj = Selection:Get()[1]
 if obj == nil or not obj:IsA('Part') then
 	return
 end
 
 GetSize(obj, gui)
 currentlySelect = obj
 return obj
end
local gui = script.Parent.ScreenGui

gui.Parent = game.CoreGui

gui.TextLabel.Text = 'TEST'

Selection.SelectionChanged:Connect(function()

currentlySelect = getObject(gui)

end)
Selection.SelectionChanged:Connect(function()

currentlySelect = getObject(gui)

end)

currentlySelect:GetPropertyChangedSignal('Size'):Connect(function()

GetSize(currentlySelect, gui)

end)

For debugging purposes, I’ve added a while true loop in a coroutine which prints the value of currentlySelected, it does print the updated value. So, the issue lies within :GetPropertyChangedSignal not being able to receive the new value.

Hoping to use Instance.new(‘Part’) to initialise the variable.

1 Like

Would this not fix your issue? If you connect the changed event to each selection when initialised?

local currentlySelect = workspace['PLUGINPart_DoNotRemove_1a2b3c4de5f6']

local function getObject(gui)
	local obj = Selection:Get()[1]
	if obj == nil or not obj:IsA('Part') then
		return
	end
	
	GetSize(obj, gui)
	currentlySelect = obj
	return obj
end


local gui = script.Parent.ScreenGui
gui.Parent = game.CoreGui
gui.TextLabel.Text = 'TEST'

Selection.SelectionChanged:Connect(function()
	currentlySelect = getObject(gui)
	currentlySelect:GetPropertyChangedSignal('Size'):Connect(function()
		GetSize(currentlySelect, gui)
	end)
end)
2 Likes

Big thanks! Seems to work. Should have tried that had I known that :GetPropertyChangedSignal works within a function. Suspected it won’t since the function is fired only once.

I went for a while not fully understanding events as well. I definitely recommend reading up about them! You can essentially connect a listener to an event in any part of your code.

1 Like