How do i save a table in DataStore?

This question was already asked, but i can’t understand how to do it, i want to save this kind of tables:


local Data = {
    Coins = 0,
    Gems = 10,
    Level = 1,
    Xp = 100
}

And i want to save those values in datastore, and be able to get each stat, for example, but how i do that?

I hope you respond me, thanks :+1:

You save it like you save any other value.

1 Like

There is a topic on this already please search the dev forum before asking questions:

edit: this topic explains it in a good detail.

6 Likes

Ok, i understand, but now, for example:

a value in leaderstats has changed, and that value = a value in a table, i’m bad at explaining, how i do that?

I am a little confused on what you mean, a data store should save the final data that player has in a game. The article I provided above :point_up_2: should have the answers to your data store problem. Could you elaborate more on what you mean? Another thing to note, if you are saving Values and not items, then there is no point in having a table, just add the data to the data store.

You shouldn’t be updating a datastore whenever a value changes; there is a limit on the number of requests you can make per minute. You should save player data:

  • when they leave the game,
  • periodically (like every five minutes or so), and/or
  • when the game closes down

Also, depending on the data you are saving you don’t really need to convert it into a JSON string. Datastores accept tables like any other value as long as it is serializable. (i.e. not containing references to any parts or other instances)

5 Likes

Let me catch you there: you don’t need to encode anything you send to a DataStore at all. This is done internally (both the key and the value need to be coerced to a string format to be acceptable for DynamoDB). JSONEncoding data you intend to save to a DataStore will just bloat how many characters your data takes up.

1 Like

Ok sorry by not responding, i forgot why i made this post:

Since my game uses alot of values, i think it should be unecessary do this:

local ds1 = DataStore:GetDataStore("1")
local ds2 = DataStore:GetDataStore("2")
local ds3 = DataStore:GetDataStore("3")
local ds4 = DataStore:GetDataStore("4")
local ds5 = DataStore:GetDataStore("5")
local ds6 = DataStore:GetDataStore("6")
local ds7 DataStore:GetDataStore("7")

And instead of having too much datastores, i want to keep one, and to do that, i must use tables i guess.

you can edit tabled rank positions and call from those positions