How to save Tables with DataStore2?

Hey, I’m brand new on DataStores2, I’ve been trying to save a Table.

Basically, I’ve got a Inventory system that just adds whatever item that’s in your Inventory as a simple StringValue in a Folder in the player.

I’ve been trying for awhile to make DataStore2 save this, could anyone help me out?
Thanks in advanced

Oh ye true this would be useful cause the increment command doesn’t work for tables.

First, when you use :Get() with a table, you don’t need to have {} inside, you can just leave it blank.
Second, instead of saving when you update it, you should save it when the player departs, when the server shuts down with game:BindToClose(), and every 100-200 seconds. Like:

local CharTable = {
    HairColor = nil,
    SkinColor = "Test"
}

local CharacterStorage = Ds2("Character", Player)

CharTable = CharacterStorage:Get() -- this loads the data

game.Players.PlayerRemoving:Connect(function()
    CharacterStorage:Set(CharTable) -- this saves the data
end)

-- not in Studio so not gonna do BindToClose, but it is pretty easy to look up

while true do
    wait(200)
    CharacterStorage:Set(CharTable)
end

Use :Set() to save, and :Get() to load.

2 Likes

Why the loop every 200 seconds and not 10 and why would you need the loop?
Also can’t you just use :Set(CharTable) every time the table is changed.

while true do

Thanks for the help too.