Storing multiple values in single DataStore

Because of the GetAsync rate limit I am looking into more efficient methods of retrieving data, how could I store multiple values in a single datastore instead of using GetAsync multiple times?

This script is what I am looking to achieve:

local datastore = game:GetService("DataStoreService"):GetDataStore("Users")
local id = game.Players.LocalPlayer.UserId

userdata = datastore:GetAsync(id)

print(userdata.name) --"Jeff"
print(userdata.points) --63
print(userdata.level) --5
1 Like

You just set a table with keys.

local toSave = {}
toSave.name = 'Jeff'
toSave.points = 63
toSave.level = 5

datastore:SetAsync(id, toSave)

Datastores automatically use HttpService:JSONEncode and HttpService:JSONDecode to convert tables to and from strings, so you can save tables and retrieve them.

3 Likes