Inventory System

I am planning to start making an inventory system for a factory game. I was wondering how to aproach making an inventory system for it. I am currently stuck between using a table to store players inventories or using instances as it would simplify networking and update handling.

I have previously tried using tables but found it annoying and difficult to work with and am leaning towards using instances instead but am worried about any performance impacts it will have.

Any tips or ideas?

I don’t think you can datastore instances. I think the best thing to do is make a table and save

local tableName = {
    ["item name"] = quantity
}

for each item and make a system that makes a ui and show the quantity of item name in an inventory gui.

Then I would save the datastore

llocal datastoreService = game:GetService("DataStoreService")
local inventoryStore = datastoreService:GetDataStore("PlayerInventory")

local oldTable = inventoryStore:GetAsync(userId) -- be sure to set userId earlier in the code

local newTable = oldTable
newTable["Item Name"] += 1

inventoryStore:SetAsync(userId,newTable)

To update old values to increase an item and make more functionality to input an instance and put this in a function and make it automatically change the inventory. Be sure to put it in ServerScriptService or ServerStorage and if you want, make it a module script which is what I would recommend.
I used that for a car gui that saves multiple cars.

Making inventory systems isn’t easy. You’ll need to:

  1. Create an item system, which need to be able to be spawned into the world, and picked up out of it.
  2. You’ll need to manage a database for items, where you’ll lookup their data with their id.
  3. You’ll need to create the inventory system, which must be able to have items added, items removed, and it needs to adhere to the capacity of the inventory
  4. You’ll need to create a UI system on the client, which will need to communicate with the server when manipulating the UI
  5. You may need a hotbar
  6. You should give every item a UID

It’s definitely not easy, it took me many tries to get a fully working system

My fault for not clarifying.
I am already aware of the fact that instances are not savable in datastores. I was thinking of converting existing instances into a table when saving occured meaning items are represented as instances instead of being kept as tables or objects l.

For example,
An item apple would have a number value child or attribute that represents its count which would have a parent folder instance which represents an inventory

Ok, I would recommend making numberValue instances then. That is what I have in place for if a car is owned or not in my system and also the stats which are numberValues and stringValues.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.