So I am trying to load a bunch of modules through a main module that is being loaded by a local script in StarterPlayerScripts. My current method of loading said modules is looping through them and requiring each one and calling in their main method(that is shared through all of the modules) :init(player: Player)
.
The Problem that I am currently facing is the fact that the modules(7 in total), do not fully load or partially load or only one or two load, causing a lot of issues since all these modules are for the User Interface. I’ve tried adding delays while looping through each module, loading each one manually, waiting for the player’s character to spawn-in, etc.
Replicated Storage and Player Scripts Workspace
Main Module Loading Protocol (UserInterface)
function UI:handleExternal()
print("[CLIENT]: Loading external modules...")
if (LocalPlayer) then
for _,module in pairs(script:GetChildren()) do
warn("[LOADING]: " .. module.Name)
local moduleReq = require(module)
moduleReq:init(LocalPlayer)
task.wait(0.11)
end
end
end
--= Initializers =--
function UI:Init() : nil
self:handleStats()
Mouse.Button1Down:Connect(function()
self:manageClicking()
end)
self:handleButtons()
self:handleButtonEffects()
self:handleGuiClosing()
self:handleExternal()
require(script.Parent.Destructible):init(LocalPlayer)
end
StartPlayerScripts Localscript (UserInterfaceSetup)
--= Services =--
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
--= Object Refrences =--
local Libraries = ReplicatedStorage.Libraries
local ClientLibraries = Libraries.ClientLibraries
local SharedLibraries = Libraries.SharedLibraries
--= Dependencies =--
local UserInterface = require(ClientLibraries:WaitForChild("UserInterface"))
--= Init =--
UserInterface:Init()