So I am trying to make a easy to use module system as in I can sort modules, name them what I want and organize them how I please. I think I have it working now and its similar to Quenty’s code of “Nevermore” just a little more simple. Anyway this allows to me run any module in the by:
local require = require(game.ReplicatedStorage:WaitForChild("Vast"))
local Format = require("Format")
local Particles = require("Particles")
Here is the code that makes it all happen.
local RunService = game:GetService("RunService")
local ServerModules = {}
local ClientModules = {}
function AddToTable(tab, location, s)
for i,v in pairs(location:GetDescendants()) do
if v.ClassName == "ModuleScript" then
local mod = v
if tab == ClientModules then
mod = v:Clone()
mod.Parent = script
elseif s then
local name = mod.Name
mod:Destroy()
mod = script[name]
end
tab[v.Name] = v
end
end
end
local function LoadModule(name, x)
if #ServerModules == 0 and RunService:IsServer() then
AddToTable(ServerModules, game.ServerScriptService.Vast.Main, true)
AddToTable(ServerModules, game.ServerScriptService.Vast.Server)
elseif #ClientModules == 0 and RunService:IsClient() then
AddToTable(ClientModules, script)
end
if RunService:IsServer() then
return require(ServerModules[name])
else
return require(ClientModules[name])
end
end
return LoadModule
Please let me know if this would be laggy or bad in anyway. It works perfectly from what I can see but I want to make sure it’s fine before adding it into my games.