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

Ordered DataStore not working?

Asked by
Jonibus 30
10 years ago

I have a script that is supposed to save players stats in a table and load them when a player joins the game. By changing the var ds to :GetDataStore opposed to :GetOrderedDataStore, it works. But for some reason this doesn't. Anyone have any idea why it doesn't save/load?

Thanks in advance.

ds = game:GetService("DataStoreService"):GetOrderedDataStore("GlobalStats_Wipe1")

game.Players.PlayerAdded:connect(function(p)
    coroutine.wrap(function()
        local stats = ds:GetAsync(p.Name.."_Stats") or {["JCoins"] = 0, ["SFKills"] = 0, ["SFDeaths"] = 0}
        local v = Instance.new("IntValue",p)
        v.Name = "Values"
        local ingame = Instance.new("BoolValue",v)
        ingame.Value = false
        ingame.Name = "InGame"
        local coins = Instance.new("IntValue",v)
        coins.Name = "Coins"
        coins.Value = stats.JCoins
        local sfkills = Instance.new("IntValue",v)
        sfkills.Name = "SFKills"
        sfkills.Value = stats.SFKills
        local sfdeaths = Instance.new("IntValue",v)
        sfdeaths.Name = "SFDeaths"
        sfdeaths.Value = stats.SFDeaths
    end)()
end)

game.Players.PlayerRemoving:connect(function(p)
    ds:UpdateAsync(p.Name.."_Stats", function(old) return {
        ["JCoins"] = p.Values.Coins.Value,
        ["SFKills"] = p.Values.SFKills.Value,
        ["SFDeaths"] = p.Values.SFDeaths.Value
        } end)
end)

Answer this question