In short
This message is a pointer, not the real error. It says the ModuleScript you passed to require crashed while it was running its top-level code. The real error is printed just above it in Output, with the module's own name and line. Fix that one and this message goes away. Two related messages: Module code did not return exactly one value (the module has no return at the end) and Requested module was required recursively (two modules require each other).
What the message means
ServerScriptService.Main:3: Requested module experienced an error while loading
Other forms of the same message:
Module code did not return exactly one valueRequested module was required recursively
require runs the module once, the first time, and keeps what it returns. If that first run errors, every script that requires it gets this message, and each require of it fails the same way.
The line number in this message is the require line in your script, not the problem. The problem is in the module.
Causes and fixes
Three things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
- The module has its own error
- The module does not return exactly one value
- Two modules require each other
The module has its own error
Any runtime error in the module's top-level code (outside its functions) breaks the load: a WaitForChild on the wrong side, a nil index, a typo.
local Config = {}
-- top-level code runs when the module is required;
-- if Settings is missing: attempt to index nil with 'GetAttribute',
-- and the script that required it gets:
-- Requested module experienced an error while loading
local settingsFolder = script.Parent:FindFirstChild("Settings")
Config.MaxPlayers = settingsFolder:GetAttribute("MaxPlayers")
return Config
Read the error just above in Output, which names the module and its line, and fix that. Keep top-level module code small and safe; do risky work inside functions that callers run later.
local Config = {}
local parent = script.Parent
local settingsFolder = parent and parent:FindFirstChild("Settings")
local maxPlayers = settingsFolder and settingsFolder:GetAttribute("MaxPlayers")
Config.MaxPlayers = if typeof(maxPlayers) == "number" then maxPlayers else 8
return Config
The module does not return exactly one value
A ModuleScript must end with return and one value (usually a table). A missing return gives Module code did not return exactly one value.
local Shop = {}
function Shop.price(itemName)
return if itemName == "Sword" then 100 else 50
end
-- forgot: return Shop
End the module with return and the table.
local Shop = {}
function Shop.price(itemName: string): number
return if itemName == "Sword" then 100 else 50
end
return Shop
Two modules require each other
If module A requires B at its top and B requires A at its top, neither can finish loading first. Roblox stops with Requested module was required recursively.
-- ModuleScript Inventory, in ReplicatedStorage:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Shop = require(ReplicatedStorage:WaitForChild("Shop")) -- Shop also requires Inventory
local Inventory = {}
function Inventory.add(itemName)
print("added", itemName, Shop)
end
return Inventory
Break the loop: move what both need into a third module, or require the other module inside the function that uses it, so it loads only when called.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Inventory = {}
function Inventory.add(itemName: string)
-- required on first use, after both modules have finished loading
local Shop = require(ReplicatedStorage:WaitForChild("Shop")) :: any
print("added", itemName, Shop)
end
return Inventory
Fix it in your place
Paste the error, RoCode fixes it in your place
Copy the line from Output and paste it here. RoCode opens the script it names in the place you have open in Studio, works out which of the causes above it is, and edits the code there instead of handing you a snippet to paste.
RoCode is an AI agent for Roblox Studio: it reads the scripts in the place you have open, finds the line and edits it there, and every change is an undo point. It runs on Windows or macOS with a desktop browser. Free to start, with free credits every day.
How to find the line that causes it
- Clear Output (Ctrl+K), press Play, and scroll up from this message to the first red line before it. That line names the ModuleScript and the line inside it that failed.
- Click that earlier line to open the module at the problem.
- If there is no earlier line, the module did not return a value or there is a require loop: check that every ModuleScript ends with
return, and that no two modules require each other at the top.
Questions
Where is the real error?
Just above this message in Output. It names the ModuleScript and the line inside it. This message is only the script that called require reporting that the load failed.
Why does every script that requires the module fail?
Because the module could not finish loading, so none of them get its value. Fix the module once and all of them work.
Can a module return a function instead of a table?
Yes, any single value works. What fails is returning nothing, or more than one value.
Can RoCode fix it?
Yes. Paste the Output lines into RoCode, including the one above this message. It opens the module in your open place, fixes its error or its return, and untangles require loops.
Sources and further reading
How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 23 October 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the message strings in Roblox Studio itself (macOS build of 13 October 2026) on 23 October 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.