PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetPropertyChangedSignal

This method returns an event that behaves exactly like the Changed event, except that the event only fires when the given property changes. It’s generally a good idea to use this method instead of a connection to Changed with a function that checks the property name. Subsequent calls to this method on the same object with the same property name return the same event.

print(object:GetPropertyChangedSignal("Name") == object:GetPropertyChangedSignal("Name")) --> always true

ValueBase objects, such as IntValue and StringValue, use a modified Changed event that fires with the contents of the Value property. As such, this method provides a way to detect changes in other properties of those objects. For example, to detect changes in the Name property of an IntValue, use IntValue:GetPropertyChangedSignal("Name"):Connect(someFunc) since the Changed event of IntValue objects only detect changes on the Value property.

Parameters

Name Type Default Description

Returns

Return Type Summary

Code Samples


Old-to-New Values with Changed

This code sample demonstrates how to save a value before a changed event fires on it in order to get more information about a change.

local part = Instance.new("Part")

-- Save the current state
local currentColor = part.BrickColor

local function onBrickColorChanged()
	local newColor = part.BrickColor
	print("Color changed from " .. currentColor.Name .. " to " .. newColor.Name)
	currentColor = newColor
end 
part:GetPropertyChangedSignal("BrickColor"):Connect(onBrickColorChanged)

-- Make some changes
part.BrickColor = BrickColor.new("Really red")
part.BrickColor = BrickColor.new("Really blue")

Changed and GetPropertyChangedSignal

This code sample demonstrates the equivalence of the Changed event and event returned by GetPropertyChangedSignal.

local part = Instance.new("Part")

local function onBrickColorChanged()
	print("My color is now " .. part.BrickColor.Name)
end

-- Manual detection of a property change
local function onChanged(property)
	if property == "BrickColor" then
		onBrickColorChanged()
	end
end

-- Connect both events
part:GetPropertyChangedSignal("BrickColor"):connect(onBrickColorChanged)
part.Changed:connect(onChanged)

-- Trigger some changes (because we connected twice,
-- both of these will cause two calls to onBrickColorChanged)
part.BrickColor = BrickColor.new("Really red")
part.BrickColor = BrickColor.new("Institutional white")