--[[
8888ba.88ba   .d888888  888888ba   .88888.   .88888.  dP    dP .d88888b      88888888b  888888ba   .d888888  8888ba.88ba   88888888b dP   dP   dP  .88888.   888888ba  dP     dP 
88  `8b  `8b d8'    88  88    `8b d8'   `8b d8'   `8b Y8.  .8P 88.    "'     88         88    `8b d8'    88  88  `8b  `8b  88        88   88   88 d8'   `8b  88    `8b 88   .d8' 
88   88   88 88aaaaa88a 88     88 88     88 88     88  Y8aa8P  `Y88888b.    a88aaaa    a88aaaa8P' 88aaaaa88a 88   88   88 a88aaaa    88  .8P  .8P 88     88 a88aaaa8P' 88aaa8P'  
88   88   88 88     88  88     88 88     88 88     88 d8'  `8b       `8b     88         88   `8b. 88     88  88   88   88  88        88  d8'  d8' 88     88  88   `8b. 88   `8b. 
88   88   88 88     88  88    .8P Y8.   .8P Y8.   .8P 88    88 d8'   .8P     88         88     88 88     88  88   88   88  88        88.d8P8.d8P  Y8.   .8P  88     88 88     88 
dP   dP   dP 88     88  8888888P   `8888P'   `8888P'  dP    dP  Y88888P      dP         dP     dP 88     88  dP   dP   dP  88888888P 8888' Y88'    `8888P'   dP     dP dP     dP 
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
The good one
]]


local ServerStorage;
local ServerScriptService;
local Players = game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local FWork = {}
local Modules = {}

FWork.Loaded = false

local SModulesFolder; 
local ModulesFolder = Replicated:WaitForChild("Package").Modules
if not RunService:IsClient() then 
	ServerStorage = game:GetService("ServerStorage")
	ServerScriptService = game:GetService("ServerScriptService")
	SModulesFolder = ServerStorage:WaitForChild("Package").Modules
end 

function FWork:Init() --initializes the module
	for _,module in pairs(script:GetChildren()) do 
		if module:IsA("ModuleScript") then 
			for i,v in pairs(require(module)) do 
				FWork[i] = v
			end
		end
	end
	for _,module in pairs(ModulesFolder:GetChildren()) do 
		if module:IsA("ModuleScript") then 
			Modules[module.Name] = require(module)
		end
	end
	if SModulesFolder ~= nil then 
		for _,module in pairs(SModulesFolder:GetChildren()) do 
			if module:IsA("ModuleScript") then 
				Modules[module.Name] = require(module)
			end
		end
	end
	for i,v in pairs(Modules) do 
		if v.Init ~= nil then 
			v:Init()
		end
	end
	wait()
	FWork.Loaded = true
end

function FWork:Get(Name) --used for getting cached modules
	if Modules[Name] ~= nil then return Modules[Name] end
end

function FWork.newModule() --used for module creation
	local Module = {}

	setmetatable(Module,{
		__index = FWork;
	})

	function Module:Init() end

	return Module
end

return FWork
