Most require() Errors and their meanings and how they occur

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

image

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”?

image
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

image

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”

image

Reproduction Script
local a = Instance.new("ModuleScript")
a:Destroy()

require(a)

Using require() on a Destroyed ModuleScript.

 

Requested module has already been destroyed

image

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

image

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

image

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.

10 Likes

Hey! Is it okay for me to make a video on this devforum post? I’ll be crediting you for the original post.

2 Likes

Especially if credit is given to the original source, which can be useful to others, absolutely fine!

1 Like

These errors are referring to scripts that have access to RobloxScriptSecurity (or RobloxScript as they’ve started calling it.)
Built-In Plugins have access to RobloxScriptSecurity API, which explains the first one. The second one is if a script without RobloxScriptSecurity access attempts to require a ModuleScript that is intended for RobloxScript usage, which most of the time these modules are intended for CoreScript/Built-In Plugin usage only.

1 Like

The error that doesn’t make sense to me, is that RobloxSecurity can’t access their lower ranked Capabilities.

PluginSecurity can. Built-In Roblox Plugins are Plugins too, but it doesn’t seem able to do that.

 

I tried it with RobloxSecurity + mixing this instance PluginCapabilities | Documentation - Roblox Creator Hub but that didn’t work either.

RobloxScriptSecurity (RobloxScript) =/= RobloxSecurity (RobloxEngine)
RobloxSecurity is strictly for the engine and CoreScripts can’t even use api under RobloxSecurity.

Again, the two errors only check if the ModuleScript requires the requiring script to have access to RobloxScriptSecurity to use it, no other securities.

Security Explanation

Securities work a bit different than what you’re thinking. Identities (like GameScript for developer scripts that are intended to run in live games and ElevatedStudioPlugin for Built-In Plugins) are given a list of securities they’re allowed to access by the engine.

For example, GameScript has access to no securities, CommandBar has access to PluginSecurity and LocalUserSecurity, etc.

Main example about the securities, StudioPlugin, the identity used for developer made plugins, only has access to PluginSecurity. Since RobloxScriptSecurity isn’t in this list, it cannot require RobloxScript modules, but can require non-RobloxScript modules.
However, ElevatedStudioPlugin, the security for Built-In Plugins, has access to PluginSecurity, LocalUserSecurity, and RobloxScriptSecurity. Since RobloxScriptSecurity is in this list, it can require RobloxScript, but not non-RobloxScript

I… hope I explained that well enough, sorry if it’s a bit over the place.

I’m not sure how to get PluginCapabilities to work (adding RobloxScript and RobloxScriptSecurity to permissions in separate tests and creating a ParabolaAdornment still errors,) but it’s probably not related to securities and instead the other capabilities tied to certain instances (DataStoreService has a “Data” capability internally for example).

2 Likes

The only thing I know about PluginCapabilities is that there’s FFlagStudioPluginCapabilities

Right, it’s most likely intended for something else.

Anyway, here another require() error I remembered if you want to add it to the list.

Unable to find module for asset id . Does the asset have a ModuleScript named “MainModule”?
Happens if the asset is a Model and it downloaded correctly, but it doesn’t have a “MainModule” ModuleScript.

2 Likes

Thank you so much! I’ll be crediting you at the very start of the video, and in the description at the very top!

The one I am wondering about is

Requested module experienced an error while setting Instance parents

I haven’t tried anything crazy yet to re-produce this.

1 Like