hello, i have a question, how to load all modules in my game ?
thankss
Use a for
loop and require? I’m more than sure you don’t need to load all of them if you have proper organisation of instances.
for i,v in pairs(game:GetDescendants()) do
pcall(function()
if v:IsA("ModuleScript") then
require(v)
end
end)
end
Lol glhf
You probably wanted this though.
-- make folder for modules in ServerStorage called "ServerModules"
-- in ServerStorage.Script:
for i,v in pairs(game.ServerStorage.ServerModules:GetChildren()) do
if v:IsA("ModuleScript") then
local success, err = pcall(require, v)
if not success then
print(v:GetFullName(), err)
end
end
end
-- make folder for modules in ReplicatedStorage called "ClientModules"
-- in StarterPlayer.StarterPlayerScripts.LocalScript
for i,v in pairs(game.ReplicatedStorage.ClientModules:GetChildren()) do
if v:IsA("ModuleScript") then
local success, err = pcall(require, v)
if not success then
print(v:GetFullName(), err)
end
end
end
1 Like
This one seems to be a good loading module sa avoid to do game:GetDescendant, imagine you have 1 million object your game will take too much time to load
Try with object ? thanks for your reply
I’m pretty sure in a place with 1 million objects it would still take < 1 second.