A way to detect rbx-script-signal for a table changing?

Is there a way to create a Table.ChildAdded and Table.ChildRemoved connection without using a loop?
It would need to respond to table.insert and table.remove. All implementations of this don’t directly respond to that.

Use metatables, a proxy table, and the __newindex event on the proxy table. This won’t work for weak tables!

local hidden = {}
local metatable = {
    __index = hidden,
     __newindex = function(hidden, key, value)
         rawset(hidden, key, value)
         -- if value is nil do something
     end,
}
local proxy = setmetatable({}, metatable)

You set and get values in the table through the proxy as if you were accessing the table directly. Note that this won’t apply for nested tables.

2 Likes

This is what metatables solve, Avigant already said it:

tabl = {}

setmetatable(tabl,{__newindex = function(t,index,value)
    print(t,index,value)
    rawset(t,index,value)
end})

tabl.x = 5 -- prints tabl, x, 5
2 Likes

don’t forget to use rawset otherwise you’re going to get a C stack overflow

4 Likes

This is very much possible. I have used this on quite a few MMORPGs. It can be done by fusing bindable events and metatables.