'require' fails randomly on some ModuleScripts

Hello,

In multiple places, requiring a ModuleScript fails with the error “Error occurred, no output from Lua.”. Here’s the snippet of code where the script errors. The actual error is on the line where the module is required.

local ResourceSettings = Model:FindFirstChild("RESOURCE_SETTINGS");
		
if ResourceSettings then
	print("Proof it exists:", ResourceSettings, typeof(ResourceSettings), ResourceSettings.ClassName);
	SettingsData = require(ResourceSettings);
	Util.CallIfExists(SettingsData.Middleware, Model); --(Not Relevant)
end

The output then displays;

08:27:12.877  Proof it exists: RESOURCE_SETTINGS Instance ModuleScript  -  Server - Util:1060
08:27:12.879  Error occurred, no output from Lua.  -  Studio

For reference, the contents of this module script is;

return {
	Authorisation = function()
		return false
	end,
}

which is a completely valid modulescript. I’m completely at a loss here since the code was working flawlessly and the error only started an hours ago despite no changes being made.

Yes I have tried to run it in regular roblox AND restart studio, same error both times. Any help would be greatly appreciated. Note this happens in multiple places.

That is strange as hell. I’m commenting to save this thread (i’ll check back later, i’m curious too.)

Have you tried keeping the default module setup?

local module = {}

function module.Authorisation()
	return false
end

return module

found out what the error was. a module script had an empty string in it and that somehow broke everything?

In your original code segment, you didn’t show a string. Was this something you added later? I’m confused.

Instead of requiring the script itself, it appears that you are attempting to require a ModuleScript object. The path to the script must be provided as a string when requiring a script, as shown here:

SettingsData = require(ResourceSettings.Source);

You should be able to correctly need the script as a result.

You can use the GetChildren method to retrieve a list of all the children of ResourceSettings, then search for the script among those children if you want to require the script that is inside the ResourceSettings object:

local script = nil
for _, child in pairs(ResourceSettings:GetChildren()) do
  if child:IsA("ModuleScript") then
    script = child
    break
  end
end

if script then
  SettingsData = require(script)
  Util.CallIfExists(SettingsData.Middleware, Model)
else
  error("Could not find ModuleScript inside RESOURCE_SETTINGS")
end

I hope this is useful. If you have any queries, please contact me.

There was an empty string in a different unrelated modulescript which somehow broke the other one. It makes 0 sense to me.

roblox be wack sometimes, unfortunately

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.