Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local ServerScriptService = game:GetService("ServerScriptService")
- local RunService = game:GetService("RunService")
- local StarterPlayer = game:GetService("StarterPlayer")
- local StarterPlayerScripts = StarterPlayer.StarterPlayerScripts
- local IsServer = RunService:IsServer()
- local RootDirectory = if IsServer then ServerScriptService else Players.LocalPlayer:WaitForChild("PlayerScripts")
- local ModuleDirectory = if IsServer then RootDirectory.Services else RootDirectory:WaitForChild("Controllers")
- local function RequireModule(Module: ModuleScript)
- if not Module:IsA("ModuleScript") then
- return
- end
- local Import = require(Module)
- local OnStart = Import.OnStart
- if OnStart then
- task.spawn(OnStart)
- end
- end
- return function()
- for _, Descendant: ModuleScript in ModuleDirectory:GetDescendants() do
- RequireModule(Descendant)
- end
- if not IsServer then
- ModuleDirectory.DescendantAdded:Connect(function(Descendant: ModuleScript)
- RequireModule(Descendant)
- end)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement