Listening to field changes in a table (OOP Object Replication)

I want to listen to a field change in a Class Object/Instance.

The issue is that I don’t know how I can listen to a field change in a table.

The reason I need to do this is so that I know when to replicate my Object(s)/Instance(s) to the client(s) when something is changed

I have tried to Google for solutions and I have looked for solutions on the Developer Hub but I couldn’t find anything.

I Script my Classes like shown here or below if that matters

Class = {}
Class.__index = Class

function, MyField2)
    local newclass = {}
    setmetatable(newclass, Class)

    newclass.MyField1 = MyField1
    newclass.MyField2 = MyField2

    return newclass
1 Like

You use an empty proxy table with the __newindex metamethod.


You’re trying to solve a problem caused by a design choice, and not the design choice itself. Consider if you actually need the server and client to keep an object with synced properties, and what use would this have? Maybe what you’re trying to achieve is possible via a more idiomatic approach.

Here’s a similar thread, with an underrated reply: How Do I Work With Remote Events In Modular OOP?