Skip to content

Instantly share code, notes, and snippets.

@nezuo
Created May 12, 2020
Embed
What would you like to do?
--< Services >--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local StarterPlayer = game:GetService("StarterPlayer")
local RunService = game:GetService("RunService")
--< Variables >--
local ModuleLookup = {}
--< Functions >--
local function AddLocation(location)
for _,descendant in ipairs(location:GetDescendants()) do
if descendant:IsA("ModuleScript") and descendant:FindFirstAncestorOfClass("ModuleScript") == nil then
if ModuleLookup[descendant.Name] then
warn("Two or more modules of name \"" .. descendant.Name .. "\" already exist. Try renaming them.")
else
ModuleLookup[descendant.Name] = descendant
end
end
end
end
--< Initialize >--
if RunService:IsServer() then
AddLocation(ServerScriptService.Server)
AddLocation(ReplicatedStorage.Shared)
elseif RunService:IsClient() then
AddLocation(StarterPlayer:WaitForChild("StarterPlayerScripts"):WaitForChild("Client"))
AddLocation(ReplicatedStorage.Shared)
end
--< Module >--
local function Import(identifier)
if ModuleLookup[identifier] then
return require(ModuleLookup[identifier])
else
error("Attepmt to import an invalid identifier. \"" .. identifier .. "\" does not exist.")
end
end
return Import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment