Module failing to load with no error message

Hi, I’m trying to require my NpcHandler module but somewhere down the line something is failing and I’m getting the “Requested module experienced an error while loading” shown below. The output normally tells me which script and line is causing the exact error, but for some reason it’s failing to now?

Output Error

Does anybody know of any reason it wouldn’t tell me which script & line the error’s coming from? I had the same issue a few days ago on a completely different game and spent ages using breakpoints to find the source, but that’s just too tedious to do every time.

Can you include the module code.

The error is because there’s code in the module script that made it impossible to compile. This could be a lot of things but if you post the code in the module we can probably help you.

As kingdom5 stated, we need the module script to understand why this is breaking.

If you are unable to share the module with us, try adding breakpoints in the module, and step through til it breaks, or several Prints in the module.

I found the error, but that’s not my problem really. My problem is that the output didn’t tell me where to find the error, and I have no idea why. It makes debugging really tedious using breakpoints whenever there’s an error.

In case you’re curious, down the line somewhere I was trying to clone a nil value which obviously wouldn’t work.

My ModuleScript (see below) throws an error just fine, is it possible you are wrapping the concerned line in a pcall?

ModuleScript
local module = {}

local a
a:Clone()

return module
Error
  17:27:36.246 - ServerScriptService.Script.ModuleScript:5: attempt to index nil with 'Clone'
17:27:36.247 - Stack Begin
17:27:36.248 - Script 'ServerScriptService.Script.ModuleScript', Line 5
17:27:36.248 - Stack End
  17:27:36.249 - Requested module experienced an error while loading
17:27:36.250 - Stack Begin
17:27:36.251 - Script 'ServerScriptService.Script', Line 1
17:27:36.251 - Stack End

There was no pcall involved. My NpcHandler called the .new() method on an npc without passing through the model, at which point the Npc constructor errored. I’d post the code but there really isn’t anything weird going on, it’s as straightforward as it sounds and just wasn’t showing the error. I can post the code if you’d like though.

I had a similar problem a few days ago on a completely different game so was hoping somebody else had experienced the same problem.

-- Local Script --
local NpcHandler = require(Classes.NpcHandler)


-- NpcHandler Module --

local Classes = game:GetService("ReplicatedStorage").Classes.Server
local Npc = require(Classes.Npc).new() -- Errors on this line

-- Npc Module --

local Npc = {}
Npc.__index = Npc

function Npc.new(model) -- No model was passed through
    local self = setmetatable({}, Npc)	
    self.localModel = model:clone() -- Errors here with no message
    return self
end

return Npc 

This is the code that broke.

There’s either an issue with your code, syntax or other in the module, it’s not at the target location or it’s not returning one value. Please include the code.

This is because you don’t return Npc at the final or you have used something that yields that makes the Module Script to don’t return anything

Thanks for the suggestion, but it does return Npc at the end of the module. Even in that case, would it not give me a different error as I’m calling .new() on a nil value? I can’t think of a feasible reason it wouldn’t give me some error.

Again, I’ve fixed the bug but have no idea why it didn’t tell me where it was.

I tried to replicate the hierarchy after copy pasting the given script source did throw up an error. My current setup which attempts to replicate the hierarchy still throws an error and is as follows:

LocalScript
local Classes = game:GetService("ReplicatedStorage").Classes.Server
local NpcHandler = require(Classes.NpcHandler)
Npc
local Npc = {}
Npc.__index = Npc

function Npc.new(model) -- No model was passed through
    local self = setmetatable({}, Npc)	
    self.localModel = model:clone() -- Errors here with no message
    return self
end

return Npc 
NpcHandler
local NpcHandler = {}

local Classes = game:GetService("ReplicatedStorage").Classes.Server
local Npc = require(Classes.Npc).new()

return NpcHandler
Error
  20:08:38.048 - ReplicatedStorage.Classes.Server.Npc:6: attempt to index nil with 'clone'
20:08:38.049 - Stack Begin
20:08:38.050 - Script 'ReplicatedStorage.Classes.Server.Npc', Line 6 - function new
20:08:38.050 - Script 'ReplicatedStorage.Classes.Server.NpcHandler', Line 4
20:08:38.050 - Stack End
  20:08:38.051 - Requested module experienced an error while loading
20:08:38.051 - Stack Begin
20:08:38.052 - Script 'Players.ankurbohra04.PlayerScripts.LocalScript', Line 2
20:08:38.052 - Stack End

I’m really curious as to why this doesn’t work for you, could you manage to make a repro file or share the full content of the Npc module? That being said, I completely understand if you don’t wish to do so.

Thank you for your help. I’d rather not post the entire code publicly, but I’ll try and replicate it in a simpler script asap and get back to you. Thank you for your help.

1 Like