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

Having trouble with getting leaderstats to save, can anyone see the issue?

Asked by 5 years ago
Edited 5 years ago

So for this I'm using the default roblox leaderboard. (With the deaths value changed to Ls.) Here's the code on my save script :

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("KillSaveSystem")
local ds2 = datastore:GetDataStore("LSaveSystem")

game.Players.PlayerAdded:connect(function(player)
    local folder = Instance.new("Folder", player)
    folder.Name = "leaderstats"
    local kills = Instance.new("IntValue", folder)
    kills.Name = "Kills"
    local ls = Instance.new("IntValue", folder)
    ls.Name = "Ls"

    kills.Value = ds1.GetAsync(player.UserId) or 0
    ds1:SetAsync(player.UserId, kills.Value)

    kills.Changed:connect(function()
    ds1:SetAsync(player.UserId, kills.Value)

    end)

    ls.Changed:connect(function()
    ds2:SetAsync(player.UserId, ls.Value)

    ls.Value = ds2.GetAsync(player.UserId) or 0
    ds2:SetAsync(player.UserId, ls.Value)

    end)
end)

Any ideas as to why it's not functioning properly?

0
Is leaderstats the value itself? Shouldn't the value be inside of leaderstats? Knineteen19 307 — 5y
0
So it would be like ls.*Insert Value Name Here*.Value instead of ls.Value, Right? Knineteen19 307 — 5y
0
Also you need to add a load system, right now it doesn't load when you start up, it only loads right after it saves. Make so the leaderstats thing loads like the kills does. Knineteen19 307 — 5y
0
So put the :GetAsync() before or after the changed event. Knineteen19 307 — 5y
0
its more conventional to save a table of values, rather than saving each value to a separate datastore. ie: local DataToSave = {Level, Money} Gey4Jesus69 2705 — 5y

Answer this question