I am doing a Module Script but confused on where exactly I should put the return statements in the Module Script itself. As I understand, with my current script, I should return the “module” table and the “monsters” table. I tried putting the return statements in different places in the script but it still doesn’t work and I either can’t call the “monsters” table or the functions from another script.
I would be glad if someone could explain where to put the return statements in simple terms and why exactly they should be there.
Here is the Module Script:
local module = {}
module.MyFunction = function()
print("6365")
end
module.Countdown = function(num1, num2, inc, prefix)
for i = num1, num2, -inc do
print(prefix..i)
wait(1)
if i == 1 then
print("The game starts")
end
end
end
local monsters = {
["Dragon"] = {
["Cost"] = 400; -- Subtable
["Health"] = 50;
};
["Bear"] = {
["Cost"] = 500;
["Health"] = 70;
}
}
return module
return monsters
So module scripts can only return one table. Nothing higher or lower. It should also be always at the bottom. If you want to include the monsters table inside of the return table, instead of local monsters, you could write module.monsters, so that the monsters table is apart of your module. And then remove return monsters and you’ll be able to access your monsters table by requiring the module and calling the monsters index.
I have an impression that ModuleScripts can return anything as long as exactly one value (which could be anything, for example strings, functions, numbers, threads, etc.) is returned rather than just one tables? Do you have any evidence (e.g. from Roblox documentation, though it may be wrong) to support the statement that ModuleScripts cannot return anything other than tables?