Roblox Luau · ModuleScripts

Roblox ModuleScript Not Working? Fix Require and Return Errors

When a ModuleScript fails, the cause is often a missing return, requiring from the wrong side, circular dependency or code running before the module is ready.

Updated September 2026 · 7 min read · Stellar AI
Use this prompt in Stellar AI:

“My Roblox ModuleScript is not working. Here is the module, where it is stored, the require line and the Output window error. Diagnose the most likely cause first, then give me the smallest safe patch and a test checklist.”

Fix this with Stellar AI →

Confirm the module returns something useful

A ModuleScript is usually required because another script expects it to return a table, function or value. If the module runs code but never returns the expected API, the requiring script may receive nil or behave as if the module is empty. Start by opening the module and checking the last meaningful line. A clear pattern is to create a local table, attach functions to it, and return that table. If the module is meant to return one function, return that function intentionally.

Do not hide setup logic inside the module unless the caller expects it. A reusable module should be predictable: require it, call the function, get the result. If the module changes game state as soon as it is required, it becomes harder to debug and can behave differently depending on which script loads it first.

local MyModule = {}

function MyModule.DoThing(player)
    return true
end

return MyModule

Check where it is stored

Location matters. Code that needs to be shared by both client and server can live in a replicated container. Code that must remain trusted should be server-only. If a LocalScript tries to require a module in a place it cannot access, the Output window will usually show a path or permission-style error. If a server script requires a client-only module, the architecture is probably wrong. Decide whether the module is shared utility, client UI logic or trusted server logic.

Ask Stellar AI to review the module location, the requiring script type and the intended use. The best patch will not simply move everything to a shared location. It will keep trusted rules on the server and expose only safe shared helpers to the client.

Avoid circular dependency chains

Circular requires happen when Module A requires Module B while Module B also requires Module A, sometimes through a third module. This can freeze setup or return incomplete values. If your module works alone but fails in the full system, list the require chain. Simplify the design so shared constants live in a small independent module, and feature modules depend on that shared module instead of on each other.

Test one function at a time

Make a small test script that requires the module and calls one function with simple input. If that works, test the real caller. If the test script fails, the issue is inside the module or require path. If the test script works but the real caller fails, the issue is timing, script side or arguments. Keep Output open and copy the first useful error with the line number.

After patching, test in Play mode with the real player flow. Confirm that the module loads once, returns the expected API, and does not rely on objects that have not been created yet. A stable module is simple to require, easy to test and clear about whether it is client-side, server-side or shared.

Fix the module path

Paste the module, require line and Output error into Stellar AI. Ask for a minimal patch and a one-function test.

Open Stellar AI free →