Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Shared = require(ReplicatedStorage:WaitForChild("Shared"))
- local Services = script:WaitForChild("Services")
- -- // A "Service" simply returns to a server-sided script.
- local RequiredServices = {}
- for _,Service in ipairs(Services:GetDescendants()) do
- -- // We use ipairs because GetChildren() returns an array, which has Index = Value pairs. ipairs.
- if Service.ClassName ~= "ModuleScript" then
- continue
- -- // Continue forces a loop to it's next iteration, it is an alternative to;
- --[[
- if Condition then
- -- Code
- end
- -- // This is called indentation reduction.
- ]]
- end
- RequiredServices[Service.Name] = require(Service)
- -- // ex; ServiceTemplate = {Init = function(), Start = function()}
- end
- -- // The reason we run this loop is because we must iterate through all the services twice.
- -- // Once to run all Init() functions, and once those are done, again to run Start() functions.
- -- // The point of Init() functions is to setup things that will be used in other scripts, in the other scripts Start().
- _G.GetService = function(Service)
- for Name, Module in RequiredServices do
- if Name == Service then
- return Module
- end
- end
- error("Could not find service :"..Service)
- end
- for Side, Table in Shared do
- if Side == "Client" then
- continue
- end
- for Name, Function in Table do
- _G[Name] = Function
- end
- end
- for Name, Service in RequiredServices do
- if Service.Init then
- Service.Init()
- end
- end
- for _,Service in RequiredServices do
- if Service.Start then
- Service.Start()
- end
- end
- for _,Service in RequiredServices do
- if Service.Secondary then
- Service.Secondary()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement