Can requiring a ModuleScript by AssetId fail?

If a ModuleScript object is has its Name property set to ‘MainModule’ and is uploaded to Roblox as a model to your account, Scripts can use require with the uploaded model’s AssetId instead. This allows you to create private modules on your Roblox account!

I’m Obviously not asking about cases where the item has been moderated, has an invalid id, not a ModuleScript, not public nor owned by me and the ModuleScript content itself doesn’t error

I’m asking if in a perfectly normal circumstance it could fail under these conditions:

  1. I created the module
  2. I own the module
  3. I upload the Module correctly
  4. I input the AssetId correctly
  5. Required from a Script (Server context)

If not I wouldn’t have to bother pcalling it.

Since requiring by ID is a web request, I would assume it can fail for network related reasons.

2 Likes

I would assume that too but since it’s critical that a required ModuleScript runs it wouldn’t be surprising if there might be an auto retry / pcall behind the scenes.

and I rather not assume but be sure of what is really happening

If you don’t make the module named “MainModule” it will error

I have not personally seen a ModuleScript required by AssetId fail, but because it is a web request there is a possibility that it will.

That being said, I am unsure as to whether Roblox implements a recursive try-catch until it finally returns a proper response, but I doubt that is the case.

The smartest thing would be to implement some sort of error handling to handle cases where it might fail. Sorry if this response isn’t quite what you were looking for.

As far as I know, there are three ways in which calling a module by AssetId would fail:

  1. There is no guarantee that the script will be able to successfully grab the module from the network
  2. All module scripts that are going to be required by AssetId must be named “MainModule”
  3. The module script contains any unknown variable, functions (including the params), events, and methods. Eg. using game or workspace will not work because they are undefined in the Asset (unless you do define them)