I encountered one very unusual require()
function error, and started wondering how many there are. So here’s eventually all of the require()
errors that you can encounter.
List
Module code did not return exactly one value
Reproduction Script
local a = Instance.new("ModuleScript")
a.Source = ""
require(a)
Your ModuleScript has no return
or is returning a tuple (multiple values), instead of one value.
If you need to return multiple values, you can store them in a table. You can also return functions and more.
Requested module was required recursively
Two ModuleScripts use require()
on eachother directly, and the game detects it beforehand and throws this error.
Downloading asset failed for asset id X. Is the asset id correct and is the asset type “Model”?
Using require(<AssetId>)
on a bad To use require
with an Asset ID, you need a ModuleScript
named MainModule uploaded. If it still errors, it’s due to permissions on Roblox, e.g. Group Modules cross-requiring from Users or something else.
InsertService
doesn’t have this issues with detecting if you have permissions to access a ModuleScript on a Group, so you could use that instead.
Unable to find module for asset id X. Does the asset have a ModuleScript named “MainModule”?
Occurs if the Asset Id was downloaded successfully, but a ModuleScript named MainModule
was not found. The ModuleScript named MainModule
needs to be right-clicked and saved to Roblox, for that Asset Id to work with require()
.
Attempted to call require with invalid argument(s).
Bad argument provided to the function.
Requested module experienced an error while loading
The ModuleScript has an error somewhere, usually there is more context underneath the error, that you can click on. Chained ModuleScripts will also throw this error if one of their ModuleScripts errored, in a way where it fails to load.
Requested module experienced an error while setting Instance parents
I am not exactly sure how this can happen yet. Maybe it has to do with a mixture of InsertService or other. Maybe Actor Scripts?
Warning: “require() should not be called on a destroyed ModuleScript, this will become an error in the future”
Reproduction Script
local a = Instance.new("ModuleScript")
a:Destroy()
require(a)
Using require()
on a Destroyed ModuleScript.
Requested module has already been destroyed
Either you have:
-
DFFlagDestroyedModuleRequireWarning
is false -
DFFlagDestroyedModuleRequireError
is true
or Roblox updated and made this change
Using require()
on a Destroyed ModuleScript.
Cannot require a non-RobloxScript module from a RobloxScript
For instance, you have a Built-in Plugin trying to use require()
on a ModuleScript that you’ve created manually in Studio.
This error doesn’t make sense to me, because PluginSecurity doesn’t have this issue. And if it would, it would be very problematic for technical Plugins.
Cannot require a RobloxScript module from a non RobloxScript context
For instance, you can reproduce this by having a Plugin in the Built-In, move a ModuleScript from its environment onto the Workspace, and then manually using require()
onto that ModuleScript.