Roblox Studio error

Requested module was required recursively

What Requested module was required recursively means in Roblox Studio, the two things that cause it with the code that triggers each, and the fix for each one.

Updated 12 November 20263 min readErrorLuauWritten by

In short

Module A requires module B, and B requires A (directly, or through more modules). When A starts loading, B starts, then B asks for A, which has not finished yet, so Roblox stops with this error. Break the loop: move what both need into a third module, pass one module to the other instead of requiring it, or require it inside the function that uses it.

On this page
  1. What it means
  2. Causes and fixes
  3. Fix it with RoCode
  4. Find the line
  5. Questions
  6. Sources

What the message means

Output (example)
ReplicatedStorage.Inventory:1: Requested module was required recursively

Other forms of the same message:

  • Requested module was required recursively. To allow circular dependencies, all modules in the cycle must use `export` instead of `return`

The loop can be long: A requires B, B requires C, C requires A. Read the require lines at the top of each module named in Output to find it.

Recent Studio builds print a longer form of the message that mentions Luau's export syntax for modules in a cycle. The fixes on this page work in every version and keep your modules simple.

Causes and fixes

Two things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.

Two modules require each other at the top

Inventory needs a price from Shop, and Shop needs to add items to Inventory. Each requires the other on its first lines.

Breaks ModuleScript in ReplicatedStorage named Inventory
-- ReplicatedStorage.Inventory
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Shop = require(ReplicatedStorage:WaitForChild("Shop"))

local Inventory = {}

function Inventory.valueOf(item)
    return Shop.priceOf(item)
end

return Inventory

Move the data both need into a third module that requires neither. Here the prices live in ItemData, and both modules read them from there.

Fixed ModuleScript in ReplicatedStorage named Inventory
-- ReplicatedStorage.Inventory
local ReplicatedStorage = game:GetService("ReplicatedStorage")

type ItemDataModule = { Prices: { [string]: number } }
local ItemData = require(ReplicatedStorage:WaitForChild("ItemData")) :: ItemDataModule

local Inventory = {}

function Inventory.valueOf(item: string): number
    return ItemData.Prices[item] or 0
end

return Inventory

The other module is only needed later

Sometimes a module only needs the other one inside a function that runs long after loading. Requiring it at the top still creates the loop.

Breaks ModuleScript in ReplicatedStorage named Rounds
-- ReplicatedStorage.Rounds
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Rewards = require(ReplicatedStorage:WaitForChild("Rewards"))

local Rounds = {}

function Rounds.finish(winner)
    Rewards.give(winner)
end

return Rounds

Require it inside the function. By the time the function runs, both modules have finished loading, and require returns the cached module.

Fixed ModuleScript in ReplicatedStorage named Rounds
-- ReplicatedStorage.Rounds
local ReplicatedStorage = game:GetService("ReplicatedStorage")

type RewardsModule = { give: (winner: Player) -> () }

local Rounds = {}

function Rounds.finish(winner: Player)
    local Rewards = require(ReplicatedStorage:WaitForChild("Rewards")) :: RewardsModule
    Rewards.give(winner)
end

return Rounds

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.

For example: ReplicatedStorage.Inventory:1: Requested module was required recursively

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

  1. Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
  2. Find the first red line. It starts with the script's place in the Explorer and the line number, such as ServerScriptService.Shop:12:.
  3. Click the red line. Studio opens that script with the cursor on the failing line.
  4. Read the lines between Stack Begin and Stack End under it: they list the calls that led there, newest first, so you can see which function called the broken one.
  5. Still not sure which value is wrong? Add print(typeof(x), x) just above the line, or set a breakpoint on it and read the values in the Watch window.

Questions

How do I find the loop?

Start at the module named in Output. Write down each module it requires, then each module those require. The loop is the module that appears twice.

Is requiring inside a function slow?

No. Roblox runs a module once and caches its value, so later require calls return the same table straight away.

Why did this start after I added one line?

One new require is enough to close a loop between modules that were fine before.

Can RoCode fix it?

Yes. Paste the Output line into RoCode. It traces the requires in your place and moves the shared part so the loop is gone.

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, 12 November 2026), and every block marked Breaks compiles and fails only when it runs. The message wording was checked against the strings in Roblox Studio itself (macOS build installed on 12 November 2026) on 12 November 2026. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.

More Roblox errors

All Roblox Studio errors

Stop hunting errors line by line.

RoCode reads the scripts in your open place, fixes the error where it happens and tells you what it changed. Free every day, no card required.