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?