In short
require() only loads a ModuleScript. It got something else: nil (a wrong name or path, or a FindFirstChild that found nothing), a module that has not reached the client yet, or an object with the right name that is a Script, a LocalScript or a Folder. Print typeof(x) and x.ClassName for the value you pass. Use the exact path, WaitForChild in LocalScripts, and make sure the object is a ModuleScript.
What the message means
ServerScriptService.ShopServer:4: Attempted to call require with invalid argument(s).
A ModuleScript holds code that other scripts share. require(module) runs it once and hands back what it returned, usually a table of functions. Roblox checks the argument first, and anything that is not a ModuleScript (or a valid path or asset ID) fails with this message before any module code runs.
If the argument is right but the module itself breaks while running, you get a different error: Requested module experienced an error while loading.
Causes and fixes
Three things cause this error in practice. Each one below has the smallest code that triggers it, then the fix.
- The path points at nothing
- A LocalScript requires a module that has not arrived yet
- The object is a Script or a Folder, not a ModuleScript
The path points at nothing
A misspelt name, a module that sits in a different folder, or a FindFirstChild that found nothing all give nil, and require(nil) fails with this message.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- the module is named ShopConfig, not Config: FindFirstChild returns nil
local config = require(ReplicatedStorage:FindFirstChild("Config"))
print(config)
Use the exact name and path from the Explorer. If the module might be missing, check the result before you require it so the warning says what is missing.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local configModule = ReplicatedStorage:FindFirstChild("ShopConfig")
if not configModule or not configModule:IsA("ModuleScript") then
error("ShopConfig ModuleScript is missing from ReplicatedStorage")
end
local config = require(configModule) :: any
print(config)
A LocalScript requires a module that has not arrived yet
On the client, objects in ReplicatedStorage arrive from the server after the game starts. A LocalScript that uses FindFirstChild or a dot path in its first lines can run before the module exists on that client.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- may run before Modules has replicated: require(nil)
local Modules = ReplicatedStorage:FindFirstChild("Modules")
local Util = require(Modules and Modules:FindFirstChild("Util"))
print(Util)
Use WaitForChild for every step of the path in LocalScripts. It waits until the object exists, then returns it.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Modules = ReplicatedStorage:WaitForChild("Modules")
local Util = require(Modules:WaitForChild("Util")) :: any
print(Util)
The object is a Script or a Folder, not a ModuleScript
Code written in a normal Script cannot be required, even if it ends with return. The same happens when a Folder or Model shares the module's name and the path finds it first.
local ServerScriptService = game:GetService("ServerScriptService")
-- Rewards is a Script, not a ModuleScript
local Rewards = require(ServerScriptService:WaitForChild("Rewards"))
print(Rewards)
Move the shared code into a ModuleScript: right-click the parent, Insert Object, ModuleScript, paste the code and end it with return and the table. Give folders and modules different names, and check the class when you look the module up.
local ServerScriptService = game:GetService("ServerScriptService")
local rewardsModule = ServerScriptService:WaitForChild("Rewards")
assert(rewardsModule:IsA("ModuleScript"), `Rewards is a {rewardsModule.ClassName}, not a ModuleScript`)
local Rewards = require(rewardsModule) :: any
print(Rewards)
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
- Open Output (Window menu, or the Script tab), clear it with Ctrl+K (⌘K on Mac), and press Play.
- Find the first red line. It starts with the script's place in the Explorer and the line number, such as
ServerScriptService.Shop:12:. - Click the red line. Studio opens that script with the cursor on the failing line.
- Read the lines between
Stack BeginandStack Endunder it: they list the calls that led there, newest first, so you can see which function called the broken one. - 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
Can I require a module by a string path?
Yes, in current Roblox. A string path starts with ./ (from the script's parent), ../, @self/ (from the script) or @game/. Unlike WaitForChild, it does not wait: the module must already exist when the line runs.
Why does it work in Studio but not in the live game?
Usually timing. In Studio the client often loads everything before your LocalScript runs; on a real connection it may not. Use WaitForChild for modules that LocalScripts require.
Can a LocalScript require a module in ServerScriptService or ServerStorage?
No. Those containers never reach the client, so the path is nil there. Put modules that both sides use in ReplicatedStorage.
Can RoCode fix it?
Yes. Paste the Output line into RoCode. It reads the scripts in the place you have open, finds what the require line points at and fixes the path, the wait or the module type.
Sources and further reading
- Roblox Creator Docs: require. ModuleScripts, and the require-by-string path rules
- Roblox Creator Docs: ModuleScript
- Roblox Creator Docs: Instance:WaitForChild
How the code was checked: every block marked Fixed passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 4 November 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 installed on 24 October 2026) on 4 November 2026. What require accepts is from the require reference in the Roblox creator docs. A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.