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

How come leaderboard stats won't save?

Asked by
Cinorch 10
8 years ago
Edited 8 years ago
local DataStoreService = game:GetService("DataStoreService")
local leaderstats = DataStoreService:GetDataStore("TEST")
local settings={
    groupid = 0
}

game.Players.PlayerAdded:connect(function(player)
    local key = "user_"..player.userId


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

     local rank = Instance.new("StringValue", leaderstats)
     rank.Name = "Rank"
     rank.Value = player:GetRoleInGroup(settings["groupid"])

    local points = Instance.new("IntValue", leaderstats)
    points.Name = "TEST"
    points.Value = points:GetAsync(key)
    points.Changed:connect(function() points:SetAsync(key, points.Value) end)
end)

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

Try using this script (Yes I did make it myself.):

local data = game:GetService("DataStoreService"):GetDataStore("TEST")
local settings={
    groupid = 0
}

game:GetService("Players").PlayerAdded:connect(function(player)
    local key = "user_"..player.UserId  

    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local rank = Instance.new("StringValue", leaderstats)
    rank.Name = "Rank"
    rank.Value = player:GetRoleInGroup(settings["groupid"])
    local GetPlayerSave = data:GetAsync("user"..player.UserId)
    local points = Instance.new("NumberValue", leaderstats)
    points.Value = 0
    points.Name = "TEST"
    if GetPlayerSave then
        points.Value = GetPlayerSave[1] or 0
    end
end)

game:GetService("Players").PlayerRemoving:connect(function(player)
    local leaderstats = player:WaitForChild("leaderstats")
    local ToSave = {leaderstats.TEST.Value}
    data:SetAsync("user_"..player.userId, ToSave)
end)

0
It still doesn't save when I leave and rejoin a game! Sorry, didn't work. Cinorch 10 — 8y
0
Oh silly me, I made a mistake. I have edited the script and fixed it. Sorry! ObscureIllusion 352 — 8y
0
It uh... still doesn't work.. Cinorch 10 — 8y
0
I edited ONCE more. ObscureIllusion 352 — 8y
0
Yea it's not working, I don't know what's up. Cinorch 10 — 8y
Ad

Answer this question