Meta tables across scripts

Currently, I am working on a side project where I have two scripts. One, a module script with a meta table. Another that calls said module script which returns the table.

I am trying to figure out a way how to detect when it gets indexed or something new gets added to it.

Code:
Module script:

local api = {}

function api.newtable()
	local self = {}
	local secondtable = {}
	setmetatable(self, {
		__newIndex = function(Table, key, value)
			warn('new index')
			secondtable[key] = value
		end,
		__index = function(Table, key)
			warn('indexed')
			return secondtable[key]
		end,
	})
	
	return self
end

return api

Server Script

local tablee = require(workspace.Testing1).newtable()

tablee["yes"] = 'hello'

warn(tablee)

warn(tablee['yes'])

It is writing the table out in input when I call for it, although on the meta table side it is not.

Is there any way to make this work or a different way I can do this that will give me the same outcomes without using events?

1 Like

What are you using this for? This pattern has a lot of subtle problems that will get you eventually and there might be a better way.

is “__newindex” not “__newIndex”. the rest is fine.