[Open Source] PoolClass – a compact instance pool for Roblox

[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.

2 Likes

Isn’t it just reinventing next() Lua function?
Same applies to all pooling libraries by the way.

Hey, thanks a lot for the reply!

That’s fair, the current core does overlap with what next() offers. My goal was mainly to provide a small readable abstraction with an API that’s easier to extend for the use cases i have in mind, rather than to replace next(). It’s also my first published package, so I’m treating this as a starting point and learning opportunity.
I’ll make sure future additions provide value beyond a wrapper around already existing behavior.

1 Like

Ok that’s fine for a first project its just that OOP is very unnecessary here and it can be made into a function instead

In general i suggest avoiding OOP and looking into alternative patterns
Simply because clarity and simplicity wins hard but OOP adds too much indirection that removes clarity.

1 Like