[Already Exists] :DescendantChanged()

Although it may not be the most needed listener, I’d really like to see it added. Right now I am working on a plugin that produces a changelog and I don’t want to be connecting changed to 10,000 instances, when instead I could be connecting to just one. Not to mention I am sure other users would be able to make use of this to make sure if they are not using filtering enabled that their game is not being tampered with.

Furthermore, it’d be great to get a second argument for both this and changed which would pretty much be the client or server that made the change.

I’ve not got much time, hence the kind of sketchy outline, so I hope I’ve explained adequately enough.

1 Like

I could only imagine the number of changed events happening continuously in-game if this was to be implemented…

Workspace.DescendantChanged:connect(function(descendant)
print(descendant)
end)

Output:

.DescendantChanged( bool Recusive (default false) )

In this thread
The difference between Child and Descendant

Not sure it’s worth the engine having to watch for so many changes. Why not make a single recursive function and hook up changed events to all the objects? Then use DescendantsAdded/Removed to add/remove events as needed?

object.DescendantAdded:connect(function(obj)
obj.Changed:connect(function(prop)
print(prop, obj[prop])
end)
end)

Events are automatically disconnected when an object is destroyed, I believe.

1 Like

Surely it makes more sense to have one listener, than 1,000?

1 Like

Think of what’s going on in the background. .

Well, in the end you still have to connect all the events. So if you want to keep track of what object is being changed, you’re still going to have a lot of functions to feed into one major one. One example:

function DescendantChanged(obj, prop)
-- Foo
end

-- Initial scan to draw in all descendants:
local function Scan(parent)
for _,v in pairs(parent:GetChildren()) do
v.Changed:connect(function(prop)
DescendantChanged(v, prop)
end)
Scan(v)
end
end
Scan(ancestor)

ancestor.DescendantAdded:connect(function(descendant)
descendant.Changed:connect(function(prop)
DescendantChanged(descendant, prop)
end)
end)

Isn’t there already something along the lines of Game.ObjectChanged? I think that’s the same thing as this, but for the data model.

1 Like

Exactly what I needed, I had no idea this even existed.