How should I save my table?

Hello developers! I want to save a key value table, but I don’t know how to go about this. I tried using Update Async() but then I got confused, and then some people say that Set Async() shouldn’t be used at all. I’m quite stuck.

This is an example of the table:

-- {
      ["Level1"] = 0,
      ["Level2"] = 3,
      ["Level3"] = 3
   }

you can use datastore2 for this Saving tables in datastore2?

DataStore2 is not that good I would suggest you to look into this:

What’s the difference between the both of them?

DataStore2 have ordered backups + you need to call save to save each values plus it is kinda out-dated module. With ProfileService you don’t have ordered backups but you have “auto-saving” so saving tables and tbh any value are really easy.

I don’t recommend using UpdateAsync for tables but you can use SetAsync for both integers and tables. Note that tables can’t be saved in ordered data stores. It can only be used in a regular data store.

local listToSave = {
  ["Level1"] = 0,
  ["Level2"] = 3,
  ["Level3"] = 3
}

dataStore:SetAsync(player.UserId, listToSave)

And when taking out the data,

listToLoad = dataStore:GetAsync(player.UserId)

level1.Value = listToLoad[1]
level2.Value = listToLoad[2]
level3.Value = listToLoad[3]

Ooooo that sounds nice. So does it save every minute or?

Oh, I did not know that. Good to know!

1 Like

Also, when I save the data, do I use the player removing event?

I don’t really know but I’ve never experienced any data loss I would highly suggest you to use it.

1 Like

This is your preference. You can use PlayerAdded and PlayerRemoving when a player joins and leaves. And also DataStore2 is not that unreliable. But normal data store, which is the default, is less trustworthy than the others.

Oh ok, thanks for the advice!!