[Open Source] PoolClass – a compact instance pool for Roblox
Hi! I made PoolClass, a lightweight Luau object-pooling module for pivotable Roblox instances. (my first open source project)
It stores unused instances off-map, lets you retrieve them later, and clones a saved template when the pool has no remaining cached objects. It’s intended for frequently reused objects such as enemies, projectiles, VFX, or collectibles.
Installation
Add it with Wally:
[dependencies]
PoolClass = "nickszone/instancepoolclass@1.0.2"
Then run wally install.
Basic use
Create a pool, add one or more instances under a tag, then grab an instance whenever you need one:
local PoolClass = require(Packages.PoolClass)
local pool = PoolClass.new()
-- Pool an existing enemy model under the "Enemy" tag.
pool:pool({ workspace.Enemy }, "Enemy")
-- Retrieve a cached enemy.
local enemy = pool:grab("Enemy")
if enemy then
enemy:PivotTo(CFrame.new(0, 5, 0))
enemy.Parent = workspace
end
If there are no cached instances left, grab("Enemy") returns a clone of the original saved template. If the tag was never pooled, it returns nil.
Tags are optional—if omitted, the instance’s Name is used:
pool:pool({ workspace.Coin })
local coin = pool:grab("Coin")
Configuration and cleanup
By default, pooled instances are moved to an off-map position. You can change it and enable missing-tag warnings:
PoolClass._setPoolPosition(CFrame.new(0, -500, 0))
PoolClass._setDebugMode(true)
When you are finished with the pool, destroy all cached instances and templates:
pool:clean()
Feedback, bug reports, and suggestions are very welcome.