So in short, to handle all user interfaces, I tend to use modules same as if they were normal scripts, because I find it easier to manage and also because there are often many cases when we need to wait for player data to be loaded to start initializing GUI.
So my main questions are:
- Does it could cause memory leaks or performance issues?
- To my knowledge, they should run the same as if they were independant normal scripts, right?
- Considering they already run into a task thread, would it cause any issues if I were to use other new threads in them.
- If these modules were to require others modules that are stored in ReplicatedStorage or as a child (such as utils in screenshot bellow), could this also cause any issue?
Local Script
-- Roblox Services --
local PlayerService = game:GetService("Players")
-- Player Instances --
local Player = PlayerService.LocalPlayer
--------------------------------------------------
-- Local Functions --
local function InitializeModules()
for _, Module in script:GetChildren() do
task.defer(function()
require(Module)
end)
end
end
--------------------------------------------------
-- Initialization --
if Player:GetAttribute("DataLoaded") == true then
InitializeModules()
else
local IsLoaded = nil
IsLoaded = Player:GetAttributeChangedSignal("DataLoaded"):Connect(function()
if Player:GetAttribute("DataLoaded") == true then
InitializeModules()
IsLoaded:Disconnect()
IsLoaded = nil
end
end)
end
Module script
-- do everything like a normal script (variables, functions, singals ect)
-- There is no module table, as it is not a module to store things
return nil -- returning nil instead of a table
Local Script in StarterPlayerScript, with all modules inside it, each handling a different GUI.