"Requested module experienced an error while loading" error I can't fix

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.

Your module script has errors.

They should be printed just above the “Requested module experienced an error while loading” and will tell you what’s wrong.

It says module code did not return exactly one value . What does that mean?

the module has to return 1 value

local myValue = {}
return myValue -- module needs to return 1 value back this is normally a table with functions inside it
1 Like

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?

that’s fine you can use table.insert but are you returning the table at the end?

Module scripts work this way:

Module script:

local module = {} -- Table of variables to be returned
function module.foo(bar)
    -- code
module['bar'] = 'foo' -- Example of variables
return module -- The module has to be returned so that the script can later find the function


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 thaught module scripts automatically had a return function inside them when they get created, I have not edited these modules at all.

Send a code snippet of your module script and the way that you get your module scripts from a script or local script

It would be easier to tell you what’s wrong with the code if you showed the code :slight_smile:

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.