RegistryFactory is a fully type-safe registry module for Roblox Luau that makes it easy to load, validate, and access collections of data defined as ModuleScripts.
It’s designed for cases where you want:
- Centralized, validated data
- Fast lookups by name
- Strong static typing
- Clean, predictable APIs
Common use cases include item databases, abilities, configs, resources, and more.
If you are using Roblox Studio or want to manually import the module, you can get the latest version from the Releases tab, or install it from the Creator Marketplace / Toolbox.
If you are using Wally, add the following to your wally.toml:
[dependencies]
registryfactory = "possiblepanda/registryfactory@1.0.0"If you are using Pesde, run:
pesde install possiblepanda/registryfactory@1.0.0- Fully type-safe
- Zero runtime dependencies
- Optional per-module validation
- Fast O(1) lookups
- Simple, predictable API
Each registry loads all ModuleScripts in a folder:
Items
├─ Sword.lua
├─ Shield.lua
└─ Potion.lua
Each module should return a value of the same type:
-- Sword.lua
return {
Name = "Sword",
Damage = 25,
}local RegistryFactory = require(path.to.RegistryFactory)
type Item = {
Name: string,
Damage: number,
}
local Items = RegistryFactory.Create(script.Items) :: RegistryFactory.Registry<Item>local sword = Items:Get("Sword")
print(sword.Damage)
if Items:Exists("Shield") then
print("Shield exists!")
end
for name, item in Items:GetAll() do
print(name, item)
endYou can optionally validate each module as it’s loaded.
local Items = RegistryFactory.Create(
script.Items,
function(data: Item, module: ModuleScript)
assert(type(data.Name) == "string", module.Name .. " is missing Name")
assert(type(data.Damage) == "number", module.Name .. " is missing Damage")
end
) :: RegistryFactory.Registry<Item>If validation throws, registry creation will fail immediately.
Creates a registry by requiring all ModuleScript children of folder.
folder— Folder containingModuleScriptsvalidate(optional) — Function called once per module for validation
A read-only registry mapping string names to values of type T.
Returns the value associated with name.
Throws if the name does not exist.
Returns true if the registry contains an entry for name.
Returns the internal map of all registered values. This table should be treated as read-only.
Selects a random value from the registry. see more