local Ordered = { ModuleA, ModuleB, ModuleC }
local function Init()
for _, Module in next, Ordered do
local required = require(Module)
if required.init then task.spawn(required.init) end
end
end
Init()
What is your use case? You’re not going to get type-checking information out of dynamically-required modules, which makes actually working with those modules a pain and generally hurts the viability of a “module loader” pattern.
Ideally, your modules would be written such that they can be required in any order, as this allows you to more freely utilize modules within one-another, and each system can handle its own initialization internally. You’re unlikely to be able to get everything to play nice this way, in which case I’d recommend defining a specific boot sequence like in your second option/@ChiDj123’s suggestion, but you should review your code to see where you can break any ordering requirements if at all possible.