The Changed event fires right after most properties change on objects. It is possible to find the present value of a changed property by using
object[property]. To get the value of a property before it changes, you must have stored the value of the property before it changed.
If you are only interested in listening to the change of a specific property, consider using the
GetPropertyChangedSignal method instead to get an event that only fires when a given property changes.
This event does not fire for physics-related changes, like when the
CFrame properties of a
BasePart change due to gravity. To detect changes in these properties, consider using a physics-based event like
BasePart.Touched. A while-true-do loop can also work.
For “-Value” objects, this event behaves differently: it only fires when the
Value property changes. See individual pages for
StringValue, etc for more information. To detect other changes in these objects, you must use
The name of the property that changed.
This sample demonstrates the subtleties of the Changed event on normal objects and “-Value” objects.
-- Demonstrate the Changed event by creating a Part local part = Instance.new("Part") part.Changed:Connect(print) -- This fires Changed with "Transparency" part.Transparency = .5 -- Similarly, this fires Changed with "Number" part.Name = "SomePart" -- Since changing BrickColor will also change other -- properties at the same time, this line fires Changed -- with "BrickColor", "Color3" and "Color3uint16". part.BrickColor = BrickColor.Red() -- A NumberValue holds a double-precision floating-point number local vNumber = Instance.new("NumberValue") vNumber.Changed:Connect(print) -- This fires Changed with 123.456 (not "Value") vNumber.Value = 123.456 -- This does not fire Changed vNumber.Name = "SomeNumber" -- A StringValue stores one string local vString = Instance.new("StringValue") vString.Changed:Connect(print) -- This fires Changed with "Hello" (not "Value") vString.Value = "Hello"
This code sample demonstrates the Changed event firing within a parent object.
local object = script.Parent local function onChanged(property) -- Get the current value of the property local value = object[property] -- Print a message saying what changed print(object:GetFullName() .. "." .. property .. " (" .. typeof(value) .. ") changed to " .. tostring(value)) end object.Changed:Connect(onChanged) -- Trigger a simple change in the object (add an underscore to the name) object.Name = "_" .. object.Name