How to make an inventory system with DataStores

I have a simple question, how can I make an inventory system with DataStores?

I’ve attempted to do this a lot of times but I failed a lot and I’ve resorted to the DevForum. I know how to make DataStores, but I can’t find a way to save a Folder to a player, the DataStore only works when I save IntValues and StringValues to it, so it would be greatly appreciated if anyone could show me how to approach this issue. Thanks in advance.

1 Like

you can use tables in datastores, for example;

local inventory = {
[“Cash”] = 3423,
[“Weapon”] = “Katana”,
[“OwnedWeapons”] = {

  [1] = "Sword",
  [2] = "Gun"

}
}

The formatting is horrible here, but I hope you get the idea, I hope this helps?

1 Like

I’ll try this method and let you know if it works, thanks!

1 Like

You’d want to save those ‘folders’ as tables or dictionaries.

-- save this to datastore
local weapons = {'gun', 'knife', 'sniper'}

Then, you can repopulate an actual folder instance using that data.

-- Hierarchy
Folders
  Player
    Weapons
-- Repopulate
local playerFolder = Folders[player]
local folderWeapons = playerFolder.Weapons
local playerWeapons = {} -- fetch datastore here

for _, weapon in pairs(playerWeapons) do
   -- assuming you want to add an actual weapon...
   -- add each weapon to folder
   -- use 'weapon' to find the actual weapon in your game
end
1 Like

This seems like the most reasonable approach, thanks a lot. I’ll let you know if it works!