Require Not working properly?

So I’m rewriting my code for one of my systems and when I require the module it doesn’t work. It should print ‘sent’ if it worked.

Code:

CastSpell.OnServerEvent:Connect(function(Player, Wand, Start, End)
	local MainModule = require(Modules:WaitForChild("MainModule"))
	MainModule.Functions.CastSpell(false, Wand, Start, End)
	print('Sent')
end)

With Require:

Without Require:

Where is this MainModule located exactly and can we see what’s inside the module?

--<Services>--
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")

-- Server Contents
local ServerAssets = ServerStorage:WaitForChild("ServerAssets")
local Modules = ServerAssets:WaitForChild("Modules")
local MainModule_ = require(Modules:WaitForChild("MainModule"))

-- ReplicatedStorage Contents
local ClientAssets = ReplicatedStorage:WaitForChild("ClientAssets")
local Modules = ClientAssets:WaitForChild("Modules")
local Spells = ClientAssets:WaitForChild("SpellData")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")

local CastSpell = Remotes:WaitForChild("CastSpell")
local Extra = Remotes:WaitForChild("Extra")

--<Tables>--
local Server = {}
Server.Functions = {}
Server.Types = {"Regular"}

--<Functions>--
Server.Functions.CastSpell = function(Deflecting, Wand, Start, End)

Screen Shot 2021-01-07 at 12.00.46 PM

Is it me or are you calling the MainModule from inside the MainModule? Because that would make the code enter into an infinite require loop.

Thant fixed Idk why I thought of requiring the module inside the module… Thanks a lot for the help man!

I think its cause it is constantly yielding the stack because mainModule doesnt exist. Atleast from the perspective. Perhaps MainModule is a descendant on where the client doesnt get replicated to the server or vis versa