Overview
This post introduces Bookshelf.lua, a lightweight singleton module designed to help you register, access, and call methods on objects globally in your Roblox experience. Whether you’re managing UI components, systems, or any reusable game objects, this pattern helps keep things clean, centralized, and modular.
To showcase how it works in practice, I’ve also included an example usage module: Bar.lua
– a flexible, customizable status bar system for displaying health, XP, hunger, thirst, and more. These two modules are built to work seamlessly together.
Bookshelf.lua Features
- Singleton instance access (
Bookshelf:getInstance()
) - Add, get, and remove objects by key
- Call specific methods on stored objects
- Broadcast method calls to all stored objects
Bar.lua: A Use-Case Example
Bar.lua is a dynamic status bar module built for use with Bookshelf. It supports:
- Health, Armor, Hunger, Thirst, XP (with level-ups), and more
- Smooth animations using TweenService
- Visual popups for changes (XP gain, damage, level up, etc.)
- Auto-binding to Humanoids for health updates
- Stacked GUI layout with color-coded bars
Why Use This?
- Keep your systems decoupled but coordinated
- Great for game loop, UI managers, combat systems, and data-driven logic
- Reduces reliance on global variables or tight module coupling
Bookshelf.rbxm (6.7 KB)
Use case example:
-- EXAMPLE: USING THE BOOKSHELF
-- StarterPlayer.StarterPlayerScripts.Client
local BookshelfModule = require(game.ReplicatedStorage:WaitForChild("Bookshelf"))
local bookshelf = BookshelfModule:getInstance()
local Bar = require(game.ReplicatedStorage:WaitForChild("Bookshelf"):WaitForChild("Bar"))
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local healthBar = Bar.new("HealthBar", { type = "Health", positionIndex = 0 })
bookshelf:add("HealthBar", healthBar)
local xpBar = Bar.new("XPBar", { type = "XP", startLevel = 1, maxXP = 100, positionIndex = 1})
bookshelf:add("XPBar", xpBar)
local currentXP = xpBar.currentXP or 0
bookshelf:callMethod("XPBar", "update", currentXP + 25)
bookshelf:callMethod("HealthBar", "bindHumanoid", humanoid)
🚀 TL;DR: A clean and modular global registry system (
Bookshelf.lua) paired with a dynamic, animated status bar system (
Bar.lua) – perfect for managing game-wide UI and logic in Roblox.
Try it out, break it, suggest improvements! I’d love feedback on the architecture, use cases, or how you’re using it in your own games.
Work-in-Progress Notice
Still under development – updates are ongoing. Feedback is welcome!