Save a table with datastore2?

How can I save a table with datastore2?

Here’s how it should look…

local Datastore2 = require()

local DefaultValue = {Coins = 0, Gems = 0, MusicOn = true}

local PlayerData = {}

game.Players.PlayerAdded:Connect(function(Player)
PlayerData[Player.UserId] = Datastore2.Load(Player)
end)

Is this even possible with Datastore2? If not what is an alternate to this that would work?

Just do :Set(your table here) like you save anything else.

3 Likes

Use the :GetTable() and :Set() functions to do so.

So instead of

game.Players.PlayerAdded:Connect(function(Player)
PlayerData[Player.UserId] = Datastore2.Load(Player)
end)

What would it look like? I have never used DS2.

Tables aren’t special. You can do it exactly like you would do anything else.

2 Likes

What would anything else look like?

Can I just setup like a normal datastore and swap SetAsync and GetAsync for something?

https://kampfkarren.github.io/Roblox/guide/basic_usage/

2 Likes

Here are the docs for DS2 usage. It lists all the functions, + usage examples
https://kampfkarren.github.io/Roblox/

In the example it shows it updating using value instances. How can I swap those out for a table?

Should I create a separate datastore2 thingy for each item in the array? Is that how I am meant to do it?

For inventories should I create a separate store for each item? I still don’t really understand how to save inventories with DS2.