Use of a module script from the command line

Hi,
I have been following a community tutorial so that I can run code from the command line. I have been trying to use a module script, that I require from the command line. Every time I hit enter, I get

Requested module experienced an error while loading

I have replaced the inside of the module with print(“Hi”), so that’s not the issue
In the command line I put: require(game.ServerStorage.ModuleScript)

That just means something error’d in the Module Script

Are you calling it from server or local script?

Hello.

If I could see your module code, that would be awesome.

But from what I hear, your module code probably looks like this one.

local ExampleModule = {}

local exampleObject = game.ServerStorage.ExampleObject -- An example object.

function ExampleModule:ExampleFunction()
-- Function Logic
end

return ExampleModule

Try loading the variables that doesn’t instantly load in your game in the function you desire instead.

Here is the example script:

local ExampleModule = {}



function ExampleModule:ExampleFunction()
-- Try to access the target object here.
local exampleObject = game.ServerStorage.ExampleObject -- An example object.
-- Function Logic
end

return ExampleModule

Hey! Thanks for the reply. I tested it one more time and now suddenly it showed that there was an error. I’m not sure why it kept showing that other message before. But it’s weird because now I fixed the error, it keeps saying error and it keeps pointing at the same non-existent line. I removed the setprimarypart, and it still highlights line 9. I think the whole thing is just super buggy

Ahh! :slight_smile:.

You’re running the event on the module. The module repeats itself and the whole reason it does this is this line executes faster than the module defines the function.

Try running the last line from a Server Script.

  • Create a new script in ServerScriptService.
  • Paste the last line of your module there.

Also, there is another slight error.

The PrimaryPart of the object you desire to use doesn’t exist. You must set a PrimaryPart to the object before you run that line.

Hope it works! Good luck!

Something that people don’t really know is that ModuleScripts get internally cached when required from editor mode. In order for changes to apply, you basically have to reload studio. Even if the ModuleScript fails to return a module, it’s still considered a “result” that gets cached.

You can also painfully alleviate this by cloning the ModuleScript and deleting the old one.

In the video below, I first made the module purposely error. Then I fixed the code, which doesn’t do anything because the old module is still stored in cache. So I cloned the ModuleScript, deleted the old one so it can properly require it again.

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.