Trying to pass an argument from module A to module B, however, it just prints nil in module B.
Module A
local loaded_modules = {}
local function get_module(mod_name)
-- If unable to find module in the table
-- require and save the module to the table
if not loaded_modules[mod_name] then
loaded_modules[mod_name] = require(script:FindFirstChild(mod_name))
end
return loaded_modules[mod_name]
end
function TagsController:CallFunction(func_name)
-- In this case func_name is "Interact"
-- So it would call the "Interact" function of Module B
local module = get_module(self.Tag.."Module")
module[func_name](self.Instance)
end
Module B
function BooksModule:Interact(Book) -- self.Instance, which is a model
print(Book.Name)
end
module[func_name](self.Instance) is the same as module.func_name(self.Instance),
if you want to pass in self you need to do module[func_name](module,self.Instance)