Luau Scripting

Fix "Requested Module Experienced an Error While Loading"

Find the ModuleScript behind Roblox's "Requested module experienced an error while loading" error, plus causes and fixes for every other require() error.

Fix "Requested Module Experienced an Error While Loading"
On this page
  1. What the error actually means
  2. Step 1: Find the original error in Output
  3. Step 2: Find the failing module with a check script
  4. Every require() error and how to fix it
  5. Common reasons a module crashes while loading
  6. If it still doesn’t work
  7. Related guides
  8. Sources

“Requested module experienced an error while loading” means a ModuleScript crashed while require() was running it, so the script that asked for it got nothing back. The message itself doesn’t say which line failed, or even which module. This guide shows how to find the module that actually broke, gives you a script that checks every module in your game at once, and lists the other require() errors with what causes each one.

The Creator Hub covers how require() and ModuleScripts are meant to work, but it doesn’t document these error messages. The table further down combines the official docs with what developers have reported on the DevForum.

What the error actually means

When a script calls require(module), Roblox runs that ModuleScript’s top-level code once and caches whatever it returns. The ModuleScript reference says a module runs “once and only once per Luau environment”, and the server and each client count as separate environments.

If that code throws an error before it reaches its return, there’s no value to hand back. So require() fails, and the script that called it shows the generic message:

Requested module experienced an error while loading - Server - MainScript:3

Points worth knowing:

  • The line number belongs to the caller. MainScript:3 is the line with require(...), not the line that broke. Don’t go looking for the bug there.
  • The error spreads up a chain. If module A requires module B and B fails, A fails too, and so does your script. Every layer reports the same generic message, so the module at the bottom of the chain is the real problem.
  • - Server and - Client tell you which side failed. A module in ReplicatedStorage can work on one side and break on the other.

Step 1: Find the original error in Output

  1. Open View › Output in Studio, then run the game again.
  2. Find the red “Requested module experienced an error while loading” line.
  3. Look at the red lines above it. The first one that names a ModuleScript and a line number (for example ReplicatedStorage.Modules.Inventory:14: attempt to index nil with 'Name') is the real error.
  4. Click that line to jump to it, then fix it the way you’d fix any other script error.

The real error is usually a common one. If it’s attempt to index nil, see how to fix “attempt to index nil with”. If it’s X is not a valid member of Y, see this guide to the “is not a valid member” error.

Step 2: Find the failing module with a check script

Sometimes there’s nothing useful above the error. A DevForum bug report described this when a module yielded (with wait, InvokeServer, or a similar call) before it errored: only the generic message appeared. Roblox staff replied that a fix was coming, but the thread never confirmed it shipped. If you see this, or you have dozens of modules requiring each other, let a script check them one at a time.

This script finds every ModuleScript in the places you choose, requires each one inside pcall, and prints a report: which modules loaded, which failed and why, and which were still running after a few seconds.

Where it goes: create a Script in ServerScriptService and name it ModuleLoadCheck. To check the client side too, put a copy of the same code in a LocalScript in StarterPlayer › StarterPlayerScripts. The script works out which side it’s on.

-- ModuleLoadCheck: requires every ModuleScript in the chosen folders and
-- reports which ones fail or never finish loading.
-- Script in ServerScriptService, or a copy as a LocalScript in StarterPlayerScripts.

local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local TIMEOUT_SECONDS = 5
local side = if RunService:IsServer() then "Server" else "Client"

-- Folders to scan. The server can also see ServerScriptService and ServerStorage.
local roots = { ReplicatedStorage }
if RunService:IsServer() then
	table.insert(roots, game:GetService("ServerScriptService"))
	table.insert(roots, game:GetService("ServerStorage"))
end

local modules = {}
for _, root in roots do
	for _, item in root:GetDescendants() do
		if item:IsA("ModuleScript") then
			table.insert(modules, item)
		end
	end
end

local status = {}
local messages = {}

for _, module in modules do
	status[module] = "pending"
	-- Each require runs in its own thread, so one module that hangs
	-- doesn't stop the others from being checked.
	task.spawn(function()
		local ok, result = pcall(require, module)
		if ok then
			status[module] = "ok"
		else
			status[module] = "failed"
			messages[module] = tostring(result)
		end
	end)
end

task.wait(TIMEOUT_SECONDS)

local okCount = 0
for _, module in modules do
	local state = status[module]
	if state == "ok" then
		okCount += 1
	elseif state == "failed" then
		warn(`[{side}] FAILED  {module:GetFullName()}`)
		warn(`    {messages[module]}`)
	else
		warn(`[{side}] STILL LOADING after {TIMEOUT_SECONDS}s  {module:GetFullName()}`)
	end
end

print(`[{side}] Module check done: {okCount} of {#modules} modules loaded`)

What each part does:

  • roots lists where to look. The client can’t see ServerScriptService or ServerStorage, so the script only adds them on the server. Add other folders (for example workspace) if you keep modules there.
  • pcall(require, module) catches the failure instead of letting it stop the script, and keeps the error message so it can be printed next to the module’s full path.
  • task.spawn gives every require its own thread. If one module yields forever, the rest are still checked.
  • task.wait(TIMEOUT_SECONDS) gives modules that yield (data store calls, WaitForChild, and so on) time to finish before the report prints.

How to read the report:

Report lineWhat it usually means
FAILED with a specific error (a line number and message)This is the broken module. Fix that line.
FAILED with “Requested module experienced an error while loading”This module requires another module that failed. Look for that one higher up in the list.
FAILED on Server only, for a module in ReplicatedStorageThe module is client-only (for example it uses Players.LocalPlayer, which the docs say is nil on the server). That’s expected if only LocalScripts require it.
STILL LOADINGThe module is waiting for something that never arrives: an infinite WaitForChild, a long yield, or a require loop (see the table below).
Everything ok, but the game still failsThe module probably fails only in the conditions your real script creates (a player who isn’t loaded yet, a part that doesn’t exist yet). Check the order things load in.

Test the script in Studio with your own game. Each project’s modules behave differently.

Every require() error and how to fix it

The Creator Hub documents how require() works, but not most of the messages it can throw. These come from a DevForum list of require() errors and other threads, checked against the official ModuleScript and require() references.

Error messageCauseFix
Requested module experienced an error while loadingThe module’s code threw an error, or one of the modules it requires didFind the original error (Step 1) or run the check script (Step 2)
Module code did not return exactly one valueThe module has no return, or returns more than one valueEnd the module with a single return, usually a table: return MyModule
Attempted to call require with invalid argument(s).What you passed isn’t a ModuleScript: a Script, LocalScript, Folder, or nil from a wrong pathPrint typeof(x) and x.ClassName before the require and fix the path
Requested module was required recursivelyTwo modules require each otherMove the shared code into a third module, or require one of them later inside a function
A script hangs with no error at allA require loop. The Creator Hub says cyclic requires don’t produce errors and the thread can “hang and never halt”Same fix as above
Downloading asset failed for asset id X. Is the asset id correct and is the asset type "Model"?Requiring by asset ID with a wrong ID, an asset that isn’t a model, or no permission to use itCheck the ID and make sure the asset is a model you’re allowed to use
Unable to find module for asset id X. Does the asset have a ModuleScript named "MainModule"?The asset loaded, but its root ModuleScript isn’t named MainModuleRename the root module to MainModule and upload it again
Asset ID require fails only on the clientThe docs say requiring by asset ID only works on the serverRequire it from a server Script
require() should not be called on a destroyed ModuleScript (warning)The ModuleScript was destroyed before it was requiredKeep a module in place while scripts still require it, or require it before it’s removed
Requested module has already been destroyedSame cause, reported as an error instead of a warningSame fix
Cannot require a non-RobloxScript module from a RobloxScript (or the reverse)Code running with Roblox’s internal script security and normal developer code tried to require each otherUsually seen with built-in plugins or modules copied out of them. Don’t mix the two
String require (require("./Config")) errors because the module isn’t thereThe docs say require-by-string doesn’t wait for a ModuleScript to existUse WaitForChild on the module first, then pass the instance to require

A frequent case of the first row: a module that uses WaitForChild or FindFirstChild on something that only exists on one side. For the waiting side of that problem, see the “Infinite yield possible” warning guide.

Common reasons a module crashes while loading

These are the most common causes reported on the DevForum, roughly in order:

  1. An ordinary error in the module’s top-level code. A nil value, a typo in a property name, or an object that doesn’t exist yet. The module never reaches return.
  2. Wrong side. A module that touches Players.LocalPlayer, the camera, or GUIs is required from a server Script. Or a module that uses ServerStorage or DataStoreService is required from a LocalScript.
  3. Something required too early. The module runs before the parts, folders, or values it expects have loaded or replicated.
  4. A broken module further down the chain. Your module is fine, but one it requires isn’t, so the error passes all the way up.
  5. A failed call that wasn’t wrapped. Data store, HTTP, or marketplace calls can fail. If the module calls them at load time without pcall, that failure becomes a load failure.

For the last one, a common pattern is to keep top-level module code simple (create tables, define functions) and run the calls that can fail inside a function the caller runs after require has returned.

flowchart TD
    A["Requested module error"] --> B["Scroll up in Output"]
    B --> C["Original error shown?"]
    C -->|"Yes"| D["Fix the line it names"]
    C -->|"No"| E["Run ModuleLoadCheck"]
    E --> F["FAILED: read its message"]
    E --> G["STILL LOADING: yield or loop"]

If it still doesn’t work

  • Start a fresh test session after each fix. Stop the session and press Play again. A module runs only once per session, so changes you make while a test is running aren’t picked up.
  • Check both sides. Run the client copy of the check script too, since - Client and - Server failures have different causes.
  • Look at modules you didn’t write. Toolbox models and free admin systems often include modules that require others by asset ID. Those can break when the asset changes or gets removed.
  • Make a minimal test. Create a ModuleScript that only contains return {} and require it from the same script. If that works, the require is fine and the bug is inside your module.

If a module also stops your game with a long-running loop, the script timeout guide explains that separate error.

Sources

Frequently asked questions

What does "Requested module experienced an error while loading" mean?

A ModuleScript threw an error while its top-level code was running, so require() had no value to give back. The real error is in the module itself, or in another module that it requires.

Why doesn't the Output show the original error?

Usually it does, a few lines above the require error, so scroll up. A DevForum report described the original error going missing when a module yielded (for example with a wait or InvokeServer) before it failed. Roblox staff said a fix was coming, but the thread never confirmed it shipped.

Why does the error only say "- Client"?

ModuleScripts run separately on the server and on each client. A module in ReplicatedStorage can load fine on the server and fail on the client, for example because it waits for something that only exists on the server.

Can a require loop cause this error?

The Creator Hub says cyclic requires don't raise an error and can make the requiring thread hang forever. A DevForum write-up lists a separate message, "Requested module was required recursively", for two modules that require each other directly.

Related guides