Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Data Store Saving in bulk?

Asked by
dirk2999 103
6 years ago

Here's my leaderstats so far

local DataStore = game:GetService("DataStoreService")
local StatData = DataStore:GetDataStore("PlayerStats")
local CartData = DataStore:GetDataStore("Carts")

game.Players.PlayerAdded:connect(function(player)
    local getStatData = StatData:GetAsync(player.userId)
    local leaderboard = Instance.new("Folder",player)
    leaderboard.Name = "leaderstats"
    local level = Instance.new("IntValue",leaderboard)
    level.Name = "Level"
    local coins = Instance.new("IntValue",leaderboard)
    coins.Name = "Coins"

    if getStatData then
        level.Value = getStatData[1]
        coins.Value = getStatData[2]
    else
        StatData:SetAsync(player.userId, {1,200})
    end

    while wait(20) do
        StatData:SetAsync(player.userId, {level.Value,coins.Value})
    end
end)

My question is, I'm making carts that people buy and upgrade, and whatever you do saves. I was wondering if there was a way I could do like,

for i,v in pairs()

and get a whole group a values and save/load them together instead of individually. I am very new to DataStore so sorry if this is an easy solution.

0
Also, if the data for the carts is in 1 DataStore, and I add a new cart, and a returning player joins, how do I add that one value to their save while keeping their other stats saved? dirk2999 103 — 6y

Answer this question