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

Changed and GetPropertyChangedSignal

Changed and GetPropertyChangedSignal

Jun 26 2018, 11:15 AM PST

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")