Send Metatable from one Module Script to Another

Hey, I have two Module Scripts and I want to send the metatable (Including functions) from Module 1 to Module 2, and then set the send metatable from Module 1 to Module 2…

What do you mean “send”? Like through a remote?

Can you give an example of what you mean?

Can you not just return the module at the end of the code, and then just require() it?

Forgot how to document code lol
i.e

–Module1
local Module1 = {} Module1.__index = Module1

Module1.New = function()
return setmetatable({}, Module1)
end

function Module1:Func()
return “Test”
end

function Module1:Send()
require(PATH_TO_MODULE2):New()
end

return Module1

–Module2
local Module2 = {} Module2.__index = Module2

Module2.New = function(self)
return setmetatable(self, Module2)
end

function Module2:Print()
print(self:Func())
end
return Module2

says “tried to call a nil vaule”

I want to call ‘Func’ (Located in Module 1) from Module 2

You’d have to either set self to Module1 or create a function of inside of Module2 called Func.

local Module1 = {} Module1.__index = Module1

Module1.New = function()
    return setmetatable({}, Module1)
end

function Module1:Func()
    return “Test”
end

function Module1:Send()
    require(PATH_TO_MODULE2):New()
end

return Module1
local Module2 = {} Module2.__index = Module2

Module2.New = function(self)
    return setmetatable(self, Module2)
end

function Module2:Print()
    self = require(Module1).New()
    print(self:Func())
end
return Module2
1 Like

I’ve attempted to call Module 1 from Module 2, but under certain circumstances if there is a recursion, you’d get a stack overflow

But thanks I’ll try this!
:+1:

Well this is one way to approach the problem, and while it does work I have certain variables added when you can Module1 and can’t add them from module2. But thanks anyways…