I have put a module script in every character model in the game (including NPCs) , and every time I try to require the module I get an error saying that the module experienced an error while loading. I have not tested if this happens with players yet but it does happen when I require a module from a NPC , can someone tell me why this is happening?
Edit : I just tested it on a player and got the exact same error.
Right now I am using table.insert to put my values in the module. Is it this that is not working? If so how can I insert new values into the table part of the module?
local module = {} -- Table of variables to be returned
function module.foo(bar)
-- code
end
module['bar'] = 'foo' -- Example of variables
return module -- The module has to be returned so that the script can later find the function
Script:
local module = require(game.ReplicatedStorage.ModuleScript)
module.foo(bar) -- Runs function
print(module['bar']) -- Prints 'foo'
And having separate ModuleScripts in each object is very inefficient. If they all do the same thing, you should put it in ReplicatedStorage or ServerStorage and reference it from there
I think I found the problem . I assumed the code was already in the module when I created it , but it was not so I will have to make one script instead for all the players.