Let me provide you an outline for this little project of mine. I intend on using a single server script to handle the majority of the game functions, via the usage of module scripts. To use a module script, as you all know, you must use require(ModuleScript) to use it in a functional manner. However, for some reason when I am attempting to do this is just stops. No errors are returned, it just stops.
--:// Services
local serverScriptService = game:GetService( 'ServerScriptService' );
local replicatedStorage = game:GetService( 'ReplicatedStorage' );
local serverStorage = game:GetService( 'ServerStorage' );
local workspace = game:GetService( 'Workspace' );
local textService = game:GetService( 'TextService' );
--:// Constants
local framework = serverScriptService:WaitForChild( 'ThamesValleyFramework', 320 )
--:// Modules
local modulesCollection = framework:WaitForChild( 'Modules', 320 )
local modules = {}
--:// Initialise
for _, Module in pairs (modulesCollection:GetDescendants()) do
if Module:IsA( 'ModuleScript' ) then
print( 'Attempting to load '..Module.Name..'...' );
local timeDiff = os.time();
local initialModule
local success, err = pcall(function()
print("Requiring the module...") -- This prints as expected
initialModule = require(Module);
print("Module required.") -- This never prints, nothing else continues
initialModule:LoadModule();
end);
if success then
local timeDiff2 = os.time() - timeDiff;
table.insert(modules, Module.Name, initialModule);
print( 'Successfully loaded '..Module.Name..' in '..timeDiff2..' seconds.' );
else
if err then
warn( 'Failed to load '..Module.Name..'. '..err );
else
warn( 'Failed to load '..Module.Name..' due to an unknown error.' );
end
end
end
end
Does anyone know the issue and, preferably, how to go about solving it?
Do your modules have some kind of wait in their return that could be delaying progression in the script? Can you show us one of the modules that cause this issue?
--// Services
local serverScriptService = game:GetService( 'ServerScriptService' );
local replicatedStorage = game:GetService( 'ReplicatedStorage' );
local serverStorage = game:GetService( 'ServerStorage' );
local workspace = game:GetService( 'Workspace' );
--:// Constants
local signalController = {}
local signalsCollection = workspace:WaitForChild( 'SignalsCollection', 320 );
--:// Variables
local signalColours = {
signalRed = Color3.fromRGB( 231, 32, 32 );
signalYellow = Color3.fromRGB( 224, 242, 21 );
signalGreen = Color3.fromRGB( 52, 232, 39 );
};
--:// Functions
function updateSignalAspect( signal )
if not signal then
return;
end
end
function updateSignalStatus( signal )
if not signal then
return;
end
end
function signalController:LoadModule()
print("Loaded.");
end
--:// Returned Module
return signalController
There are no waits or anything. In this case, I am just asking it to print something. No processing of data or any time-wasting activities, currently.
Edit → I haven’t finished programming any module, I was making the initial framework first to ensure it works.
In addition to what @EmbatTheHybrid said when working with modules just be aware of circular dependencies which also cause errors, is this the only module?
That’s false theres a potential wait right there, personally I would immediately go into print debugging this out which you haven’t seem to done yet.
@dthecoolest has the most likely cause of your problem. All I’m doing is providing advice.
In your code you have it where the LoadModule function is required when the module is first required. However, this is unnecessary, as all code in the module only runs once when it is initially required. You could just put any code inside the LoadModule function inside a do-end block.
All code is only run once when the module is initially called. Calls after that will just return the value that was originally returned. This means that this:
function signalController:LoadModule()
print("Loaded.");
end