Saving Table to Datastore

Hello,
Would I be able to save something similar to this table or a table inside this table to a datastore?
If so, how would I need to go around it?
Table :

    [Player_UserId] {
        PackedCards {}
        NewCards {}
        DuplicateCards {}
    }
}
1 Like

Here’s a rough idea of how you’d do this:

DataStore:SaveAsync(Player_UserId, {
        PackedCards {}
        NewCards {}
        DuplicateCards {}
    }

What I have done in the past to save a table to a DataStore was use JSON.Encode() so it turns it into a string and save it that way. If you want to retrieve it, then you can use JSON.Decode() to return it back to a table.

DataStores support tables. I see no reason to do this, and it likely creates signifigant overhead internally.

2 Likes

You could definitely store it like that, but you are missing an equal sign (unless you are adding that).
Like this:

[Player_UserId] = {
   PackedCards = {}; --you can also use commas
   NewCards = {};
   DuplicateCards = {};
}
2 Likes

Here is an simple example on how to:

local PlayerData = {
		Data = {
			DataTable1 = {};
			DataTable2 = {};
		};

I hope this helps. :herb: