Saving JSON to DataStore - Bad Idea?

Hey guys!

I’m trying to save player data in Datastore. There are two ways:

  1. Make Datastore for each attribute (meaning, I would name datastore “Money” and use player ID to get data). This is useful, but if the user requires multiple attributes at the same time, I would have to get multiple values from different datastores.

  2. Make Datastore per playerId, and would get “data” key to get JSON data value. This will get the entire dataset at once, but I’m not sure if this is the most cost effective way of doing it (or possibly run into more errors during encoding and decoding).

Which would be efficient in this case? Thanks!

You don’t have to use JSON at all! You can also just save a table in the DataStore, and the table can contain everything you need while having only one datastore.

When you save the table to the DataStore, it gets saved as JSON, but when you get it, you get it back as table, meaning you don’t have to worry about encoding or decoding it.

EDIT: Heres an example:

local DS = game:GetService("DataStoreService"):GetDataStore("Data")

-- saving
DS:SetAsync("key", {
 coins = 100,
 gems = 5,
 level = 3,
 xp = 758
})

-- getting
local data = DS:GetAsync("key")
-- now you can access your data again like this:
print(data.coins)
print(data.gems)
print(data.level)
print(data.xp)