So for example you have script A which is just a regular script. You create a table, add contents to it then send it to another function required by a module.
local contents={}
contents.A=true
local module = require(script.ModuleScript)
module:LoadContents(contents)
You then try to print ‘contents.A’ in script B which is a module script.
local module = {}
function module:LoadContents(contents)
print(contents.A)
end
return module
But the output prints nil for what you just tried to print. Why is this? How do I fix this?
It doesn’t seem to print nil for me, I used your exact code. Requiring a module returns a table containing everything inside of the ModuleScript so it should work.
Essentially what you are doing when you require a modulescript is this:
local contents = {}
contents.A = true
local module = {
-- this is the table that is returned, which contains the module:LoadContents function
LoadContents = function(self, contents)
print(contents.A)
end
}
module:LoadContents(contents) -- call the LoadContents method
Using that logic, it should work, have you checked if it was a logic error (capitalization, variable names…)?