Im trying to do getmetatable on a local script and further implement the metamethod functions into the localscript from a modulescript, why you might ask, its cuz im trying to get the __newindex function to be compatiable to a function at my local script so it becomes like .Changed event from the Modulescript,
The Modulescript:
m = {}
m_metafunctions = {}
setmetatable(m,m_metafunctions)
return m
Local Script:
local m = require(game.ReplicatedStorage.Movement)
local m_metafunctions = getmetatable(m)
m_metafunctions.__newindex = function(table,key,value)
print(table,key,value)
end
I have tested it and checked for any spelling errors but there aint none, the output seems to print out nothing
You can’t edit tables through a module require, you need to edit it within the module. A way you could do it is by making a function in the module that takes a name and a function, and then edits the metatable like so:
local module = {}
local module_metatable = {}
setmetatable(module, module_metatable)
function module.UpdateMetatable(method, func)
module_metatable[method] = func
end
return module
Then you can use the UpdateMetatable function in the local script. (Make sure the passed ‘method’ is a string, e.g. “__newindex”)