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

Saving multiple values isn't working for some reason?

Asked by 8 years ago

after asking how to save multiple values, i was given a script but for some reason the value isn't showing. i've tried to fix it myself but i'm not getting anywhere. if anyone knows what's wrong with this script could you pls help me?

local DataStore = game:GetService("DataStoreService")
local Ds1 = DataStore:GetDataStore("DS")

game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new("IntValue",player)
    stats.Name = "leaderstat"

    local data = Ds1:GetAsync(player.UserId) --// Get the data.
    local gold = Instance.new("IntValue",stats)
    gold.Name = "Gold"
    gold.Value = data[1] or 100 --// And then just set the gold value to the first item in the table(or 100, if it doesn't exist).
end)

game.Players.PlayerRemoving:connect(function(player)
    print("Saving Data")
    Ds1:SetAsync(player.UserId, {
        player.leaderstat.Gold.Value, --// First position,
        someothervalue.Value, --// Second position,
        yetanothervalue.Value, --// Third, & onward.
    })
    print(player.Name.."'s Data Saved")
end)
1
Add function game.OnClose() wait(15) end --to the end of the script. This should have the game wait 15 seconds before shutting down. Issue may be the SetAsync function is not catching the value before the server shuts down. M39a9am3R 3210 — 8y

Answer this question