Hello, I have a module that requires/loads other modules and creates a global variable for them
The only point is so I don’t need to 1, keep using local module = require(path)
and for modules that need to load before their functions are needed can do so
! Before anyone says “just google it” I have, there were tons of different answers and none used in this case (that I found) !
Basically what it is/how it works:
local loader = {}
local loadedModules = {}
--// On script run
local Descendants = script:GetDescendants() -- Not always the same, might've spelled it wrong too.
for _, des in next, Descendants do
_G[des.Name] = require(des)
table.insert(loadedModules, _G[des.Name])
end
function loader:Reload()
local Descendants = script:GetDescendants() -- Not always the same, might've spelled it wrong too.
for _, des in next, Descendants do
if _G[des.Name] == nil then
_G[des.Name] = require(des)
table.insert(loadedModules, _G[des.Name])
end
end
end
function loader:ClearGlobalModules() -- Not sure if this would be used but I have it
for _, module in next, loadedModules do
module = nil -- Should turn the _G into a nil
end
end
return loader
Keep in mind I didn’t test this version, but that’s basically how it works. I thought of doing this for remotes too then randomizing names.
Yes I already know the remote thing is useless and an exploiter can go for _, global in next, _G do
and get them all
I just want to know if this is a bad thing to do, I do it cause it’s also easier than typing out each thing for each script that can access it.
Exploiter wise on the modules makes no difference, since they can easily use game:GetService("ReplicatedStorage").Modules.ModulePath