I’m currently developing a framework where during the development process, everything is situated in a typical modular framework, where you have folders with modules, and you can index those modules by doing, for example, Server.Functions.somefunction(). The server is started by one script, which simply requires the main module and calls the Load() function. Since running an entire large game under one VM is a bad idea, I made this function in an attempt to split the load in to different server scripts:
function Genesis.Containerize(Module: ModuleScript, Table)
local Container = Dependencies.ModuleContainer:Clone()
Container.Name = Module.Name
Container.Module.Value = Module
local FullName = Module:GetFullName()
local Path = string.split(FullName, ".")
local RuntimeContainer = Genesis.RuntimeContainer
local WorkingDirectory = RuntimeContainer
for I = 3, #Path - 1 do
local PathName = Path[I]
local Folder = WorkingDirectory:FindFirstChild(PathName)
if not Folder then
Folder = Instance.new("Folder", WorkingDirectory)
Folder.Name = PathName
end
WorkingDirectory = Folder
end
Container.Parent = WorkingDirectory
Container.Enabled = true
local InvokeMethod = Container:FindFirstChildOfClass("BindableFunction")
Table[Module.Name] = setmetatable({}, {
__index = function(_, Index)
return InvokeMethod:Invoke("__index", Index)
end,
__newindex = function(_, Index, Value)
InvokeMethod:Invoke("__newindex", Index, Value)
end,
})
return Table[Module.Name]
end
Where Dependencies.ModuleContainer is a Server Script containing:
--// Genesis module container
--// The primary goal of this is to separate out things at runtime but keep the framework modular in development
-- Constants --
local This = script
local ModuleObject = This:FindFirstChildOfClass("ObjectValue").Value
-- Setup --
assert(ModuleObject, "Module cannot be nil.")
local ModuleData = require(ModuleObject)
local Invoke = Instance.new("BindableFunction", This); Invoke.Name = "Invoke"
local ModuleMetatable = getmetatable(ModuleData) or {}
ModuleData.__index = ModuleMetatable.__index or function(Self, Index)
return rawget(Self, Index)
end
ModuleData.__newindex = ModuleMetatable.__newindex or function(Self, Index, Value)
rawset(Self, Index, Value)
end
local OnInvoke = function(Metamethod: string, ...)
if ModuleData[Metamethod] then
return ModuleData[Metamethod](ModuleData, ...)
end
end
Invoke.OnInvoke = OnInvoke
My problem is that in the Script performance monitor in the developer console, when running an action that is under a Containerized Module, the main server script that loaded the framework, is spiking in activity, while the containerized module is getting the Rate/s. Is this just an issue with displaying it, or did I make a mistake?