oskxzr
(IJBOL)
#1
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?
posatta
(pasta)
#2
Just do :Set(your table here)
like you save anything else.
3 Likes
Use the :GetTable()
and :Set()
functions to do so.
oskxzr
(IJBOL)
#4
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.
posatta
(pasta)
#5
Tables aren’t special. You can do it exactly like you would do anything else.
2 Likes
oskxzr
(IJBOL)
#6
What would anything else look like?
oskxzr
(IJBOL)
#7
Can I just setup like a normal datastore and swap SetAsync and GetAsync for something?
posatta
(pasta)
#8
2 Likes
Here are the docs for DS2 usage. It lists all the functions, + usage examples
https://kampfkarren.github.io/Roblox/
oskxzr
(IJBOL)
#10
In the example it shows it updating using value instances. How can I swap those out for a table?
oskxzr
(IJBOL)
#11
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.