Cool system that I like to use because I think it's easier than pathing to each module I want to require. Of corse you can build onto this to knock out duplicates or even hook up more use for Remotes and bindables. Fun fun
function CallOnChildren(Container, Function)
Function(Instance)
local Children = Container:GetChildren()
for _, Child in next, Children do
Function(Child)
end
end
local Cache = {
Modules = {},
Chunks = {}
}
CallOnChildren(game:GetService('ReplicatedStorage').YourRepo, function(Child)
if Child:IsA'ModuleScript' then
Cache.Modules[Child.Name] = Child
elseif Child:IsA'StringValue' then
Cache.Chunks[Child.Name] = Child.Value
end
end)
function Retrieve(Lib)
return require(Cache.Modules[Lib]) or error('Could not find library "' .. Lib .. '".'
end
function GetChunk(ChunkName)
return Cache.Chunks[ChunkName] or error('Not a valid chunk name "' .. ChunkName .. '".')
end |