This is a modified version of PlayerModule that has script loader module inside of it.
Here’s source code:
local Framework = {}
Framework.__index = Framework
function Framework.new(scriptParent: ModuleScript)
local self = setmetatable({}, Framework)
self.Script = scriptParent :: ModuleScript
self.TotalModules = 0 :: number
self.LoadedModules = 0 :: number
self.StartTime = os.clock() :: number
return self
end
function Framework:LoadModules()
for _, moduleScript in self.Script:GetDescendants() do
if not moduleScript:IsA("ModuleScript") then continue end
self.TotalModules += 1
task.spawn(function()
self:LoadModule(moduleScript)
end)
end
end
function Framework:LoadModule(moduleScript)
local moduleStartTime = os.clock()
local success, err = pcall(function()
require(moduleScript)
end)
if success then
local moduleEndTime = os.clock()
local moduleLoadTime = moduleEndTime - moduleStartTime
self.LoadedModules += 1
print("[" .. string.format("%.3f", moduleLoadTime) .. "s] @" .. moduleScript.Name .. " - client")
else
warn("Error @" .. moduleScript.Name .. ": " .. tostring(err) .. " - client")
end
end
function Framework:WaitForAllModules()
repeat
task.wait()
until self.LoadedModules == self.TotalModules
end
function Framework:DisplayLoadingTime()
local endTime = os.clock()
local totalTime = endTime - self.StartTime
local formattedTime = string.format("%.3f", totalTime)
if self.LoadedModules == self.TotalModules then
print("[client] loaded [" .. formattedTime .. "s]")
end
end
-- Init
local worker = Framework.new(script)
worker:LoadModules()
worker:WaitForAllModules()
worker:DisplayLoadingTime()
return nil
Pros:
Protects from getting your code stolen (universalSynInstance or i forgot how its called ignores playermodule and all of its descendants; konstant - bytecode decompiler also ignores player module, i think);
Very customizeable you can change anything about this framework in a matter of seconds since its a single modulescript!;
Cons:
idk, might be an issue with task.spawn breaking something (very rare);
How to use:
just put your module scripts (singletons, just modules) it will require them.
Example:
print("Hello World!")
return nil -- we dont need a table to run module script we can just return nil
https://create.roblox.com/store/asset/89143795005623/Modified-PlayerModule