✓ Accepted answer
Changed,
Changed is used mainly for instances that usually have just 1 property, for instance, a BoolValue or a NumberValue. However, there can be some false positives such as when the name is changed and you're only trying to know when another property is changed. Here's some example code, demonstrating how to use Changed incorrectly and correctly. I wouldn't use changed in any of my new work since it seems very inefficient compared to GetPropertyChangedSignal.
local V = Instance.new('BoolValue')
V.Changed:Connect(function(Property)
print('Value changed to '..V.Value)
end)
V.Value = true
V.Name = 'false positive'
V.Value = false
This code above is wrong in many ways. False positives are silly, and we can do better than that.
local V = Instance.new('BoolValue')
V.Changed:Connect(function(Property)
if Property == 'Value' then
print('Value changed to '..V.Value)
elseif Property == 'Name' then
print('Name changed to '..V.Name)
end
end)
V.Value = true
V.Name = 'good positive'
V.Value = false
GetPropertyChangedSignal,
Now, GetPropertyChangedSignal is much better since it checks for only a specific property. It's pretty straight forward, lol, so here's an example on how to use it.
local V = Instance.new('IntValue')
V:GetPropertyChangedSignal('Value'):Connect(function()
print('Value changed to '..V.Value)
end)
V.Value = 8
V.Name = '6ix9ine sucks xd'
V.Value = 7635
No problem.
2 comments
answered
Just to clarify there's pretty much no difference between the two functions. You might as well use :GetPropertyChangedSignal