§ How to · with Forge AI

How to make a Roblox inventory system (with AI)

By Sametcan Tasgiran, Founder & Developer·Published ·Updated

A Roblox inventory system needs five pieces: a slot grid, item stacking, drag-and-drop UI, rarity coloring, and DataStore persistence. Forge AI generates all five in 56 seconds — including a hotbar for quick access.

6 files · 230 lines · 56 seconds · 1 credit. 30-slot inventory + 5-slot hotbar.

30-slot grid

5×6 inventory grid in a slide-out panel. Configurable size. Each slot shows item icon, stack count, and rarity-colored border.

Item stacking

Stackable items (potions, materials) auto-combine on pickup. Stack size capped per-item (default 99). Non-stackable items (swords) occupy a slot each.

Drag-and-drop

Click and drag items between slots, between inventory and hotbar, or out to drop. Server validates every move.

Rarity tiers

Common / Uncommon / Rare / Epic / Legendary. Each tier has a border color and glow effect. Rare+ items get a subtle particle effect.

Quick-use hotbar

5-slot hotbar bound to keys 1-5. Tapping a key uses or equips the slotted item. Hotbar persists across sessions.

DataStore persistence

Inventory + hotbar saved to DataStore on every change (debounced 30s). Atomic UpdateAsync with retry-on-fail.

Files Forge AI ships for this prompt

6 files · 230 lines · 56 seconds · 1 credit

ServerScriptService/InventoryManager.lua

Slot operations, stack logic, validation

88 lines

ServerScriptService/InventorySaveService.lua

Debounced DataStore writes with retry

38 lines

ReplicatedStorage/Modules/ItemConfig.lua

Item definitions — icon, rarity, stack cap, useable

42 lines

ReplicatedStorage/Remotes/InventoryMove

Drag-drop slot change

instance

ReplicatedStorage/Remotes/InventoryUse

Hotbar key use

instance

StarterGui/InventoryUI.lua

Grid + hotbar + drag handler

62 lines

Sample output: ServerScriptService/InventoryManager.lua

--!strict
-- ServerScriptService/InventoryManager.lua  (Forge AI · excerpt)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ItemConfig = require(ReplicatedStorage.Modules.ItemConfig)
local SaveService = require(script.Parent.InventorySaveService)

type Slot = { itemId: string?, count: number }
type Inventory = { slots: { Slot }, hotbar: { Slot } }

local SLOT_COUNT = 30

local function getOrInit(player: Player): Inventory
    local inv = SaveService:Get(player)
    if not inv then
        inv = { slots = table.create(SLOT_COUNT, { itemId = nil, count = 0 } :: Slot), hotbar = table.create(5, { itemId = nil, count = 0 } :: Slot) }
        SaveService:Set(player, inv)
    end
    return inv
end

local InventoryManager = {}

function InventoryManager:addItem(player: Player, itemId: string, count: number): boolean
    local inv = getOrInit(player)
    local def = ItemConfig[itemId]
    if not def then return false end

    -- 1. Try to stack into existing slots
    if def.stackable then
        for _, slot in ipairs(inv.slots) do
            if slot.itemId == itemId and slot.count < def.stackCap then
                local room = def.stackCap - slot.count
                local add = math.min(count, room)
                slot.count += add
                count -= add
                if count <= 0 then SaveService:Set(player, inv); return true end
            end
        end
    end

    -- 2. Fill empty slots
    for _, slot in ipairs(inv.slots) do
        if not slot.itemId then
            slot.itemId = itemId
            slot.count = def.stackable and math.min(count, def.stackCap) or 1
            count -= slot.count
            if count <= 0 then SaveService:Set(player, inv); return true end
        end
    end

    return false  -- inventory full
end

return InventoryManager

Building a Roblox inventory system

Inventory systems are the backbone of any item-driven Roblox game. The defining quality of a good inventory: server-authoritative, fast to render, easy to extend. Forge AI ships all three.

The Forge AI inventory prompt produces a 6-file system in 56 seconds. ItemConfig.lua is the data layer — adding a new item is adding a row. InventoryManager.lua is the engine — it never needs to change as your item count grows. This separation is critical because production games end up with hundreds of items and you cannot rewrite the engine for each.

Stacking is the trick that makes inventories feel good. Picking up 5 health potions when you have 3 already should not consume 5 slots — it should stack to 8 in the existing slot. Forge's addItem function tries existing stacks first, then falls back to empty slots. The stack cap is per-item (potions stack to 99, building materials to 999, rare equipment to 1). All defined in ItemConfig.

Drag-and-drop is where most amateur inventory systems break. The client must show the drag preview, but the server must validate the final position. Forge handles this with a two-message pattern: client sends InventoryMove with from-slot and to-slot, server validates ownership and swap legality, then both sides update. The client never updates speculatively without server confirmation.

DataStore persistence is debounced. Saving on every slot change would burn your DataStore quota. Forge updates the in-memory inventory immediately (so the UI is snappy) and writes to DataStore at most every 30 seconds — or on PlayerRemoving, whichever comes first. This pattern survives crashes and disconnects without losing more than 30 seconds of progress.

See more on the Luau generator, the game builder, or browse the full blog.

Frequently asked

How do I add a new item?+

Add an entry to ItemConfig.lua: id, name, icon (asset ID), rarity, stackable (bool), stackCap (number). InventoryManager picks it up automatically. Forge can generate new items in batch with a follow-up prompt.

Can I have item categories (weapons, materials, consumables)?+

Yes. Add a 'category' field to each item. InventoryUI shows filter tabs at the top — clicking a tab visually filters slots, but the storage is unified. Categories help UX without splitting the DataStore.

How do I handle full inventory on pickup?+

InventoryManager:addItem returns false. The world drop manager (or whatever called add) handles the failure — usually by leaving the item on the ground or showing 'inventory full' toast. Forge can extend with the auto-drop pattern.

What about item attributes (level, enchantments)?+

Each Slot can have an 'attrs' table with per-instance data. Stackable items must have identical attrs to stack — items with different enchantments take separate slots even if they share itemId.

How does the hotbar persist?+

Hotbar is part of the same Inventory DataStore object. Slot assignments save on every change. Players see the same hotbar layout when they rejoin.

Related Forge AI prompts