Getting a module recursive error from a script?

Right now, I am really confused because I keep getting a "Module was required recursively" error for no reason at all.

Here is the script that errors when I try it:

-- // Game Server
-- // Variables

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ArchFramework = require(ReplicatedStorage.ArchFramework.MainModule)

---

local Arch = ServerStorage:WaitForChild("ArchServer")

local Scripts = Arch.Scripts
local Assets = Arch.Assets

local server = ArchFramework.GetServer()

-- // Script

server.Started:Connect(function(t)
	print("Started server")
	ArchFramework.Libraries.console.log(tostring(t))
end)

print("Hello, server!")

I get the error upon requiring the module, but I still am able to start the framework. (it starts just by simply requiring the main module.)

I believe this message occurs when a module requires another module that requires that module. Try checking your modules.

1 Like

This is from a regular script, I shouldn’t be receiving this error.

OK. If there is more than one module in your game, though, just make sure no modules are requiring each other.

None are, that’s why I am confused.

If you are sure of that, did you try to restart your studio?

Yes, I have already restarted Roblox Studio. It started happening out of nowhere as well.

Here is the module if you wanna take a look:

-- // Package

local Package = { }

local Plugins = script.Plugins
local Assets = script.Assets
local Settings = require(script.Settings)

-- // Variables

-- // - // Services

local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local PlayerService = game:GetService("Players")

-- // - // Packages

local ArchUtil = require(Plugins.ArchUtility)
local Signal = require(Plugins.Signal)
local Console = require(Plugins.Console)
local Types = require(Assets.Types)

-- // - // Other

Package.Version = "2.0.0b"
Package.PackageVersion = "2.0.0b"

Package.Libraries = {
	console = Console;
	dictionary = ArchUtil.dictionary;
}

local ArchServer = {
	Started = Signal.new() :: Types.ScriptSignal;
	IsStarted = false;
}
local ArchClient = {
	Started = Signal.new() :: Types.ScriptSignal;
	IsStarted = false;
	Player = PlayerService.LocalPlayer :: Player;
}

-- // Functions

local function GetVariables()
	return {
		scripts = script.Parent.Lua.Scripts;
		packages = script.Parent.Lua.Packages;
		assets = script.Parent.Assets
	}
end

local function SetupFolders(t: "Server" | "Client")
	local MainFolder = Instance.new("Folder")
	local Variables = GetVariables()
	local UserPackages, UserScripts, UserAssets = Variables.packages, Variables.scripts, Variables.assets
	
	MainFolder.Name = "Arch" .. t

	UserPackages[t].Name = "Packages"
	UserAssets[t].Name = "Assets"
	UserScripts[t].Name = "Scripts"
	
	UserAssets.Assets.Parent = MainFolder
	UserScripts.Scripts.Parent = MainFolder
	UserPackages.Packages.Parent = MainFolder
	
	if t == "Server" then
		MainFolder.Parent = ServerStorage
	else
		MainFolder.Parent = ReplicatedStorage
	end
end

local function SetupGlobalFolder()
	local MainFolder = Instance.new("Folder")
	local Variables = GetVariables()
	local UserPackages, UserScripts, UserAssets = Variables.packages, Variables.scripts, Variables.assets
	
	MainFolder.Name = "ArchGlobal"
	
	UserPackages.Global.Name = "Packages"
	
	UserPackages.Packages.Parent = MainFolder
	MainFolder.Parent = ReplicatedStorage
end

local function FinalizeSetup()
	for _, object in ipairs(ReplicatedStorage.ArchFramework:GetChildren()) do
		if object.Name ~= "MainModule" then
			object:Destroy()
		end
	end
end

--[[

	Starts the server, moving folders around and cleaning up the
	place.
	
	@returns [number] The amount of time (in ms) it took to start.
	
--]]

function Package.GetServer()
	if RunService:IsServer() then
		return ArchServer
	else
		Console.silentError("Could not fetch table 'ArchServer'.")
	end
end

function Package.GetClient()
	if RunService:IsClient() then
		return ArchClient
	else
		Console.silentError("Could not fetch table 'ArchClient'.")
	end
end

-- // Actions

if not ArchServer.IsStarted and RunService:IsServer() then
	local StartTime = os.clock()

	local ServerStarted = ArchServer.Started :: Types.CustomScriptSignal
	local ClientStarted = ArchClient.Started :: Types.CustomScriptSignal

	SetupFolders("Client")
	SetupFolders("Server")
	SetupGlobalFolder()
	
	FinalizeSetup()

	local EndTime = (os.clock() - StartTime) * 1000

	ServerStarted:Fire(EndTime)
	ClientStarted:Fire(EndTime)

	ArchServer.IsStarted = true
	ReplicatedStorage.ArchFramework:SetAttribute("FrameworkStarted", true)
end

return Package

Just to be sure, in the output error message, there should be a traceback pointing at the line the error happened (not in the normal script), check it out.

Also, try to use the ‘Find All’ window in the Studio to check for all modules that are using the require function, specifically, look for any child of the core module.

Already did that, he is the stack trace:

Alright, it seems like I am having problems with this segment of code:

if t == "Server" then
		MainFolder.Parent = ServerStorage
	else
		MainFolder.Parent = ReplicatedStorage
	end

This in my SetupFolders(t) function, I have no idea why parenting the new folder to server storage breaks it.

For testing purposes, try commenting out the MainFolder.Parent = ServerStorage line, then the MainFolder.Parent = Replicated Storage. Maybe this will give insight on the issue by showing where the source of the issue is.