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

How to make a data persistence leaderboard?

Asked by 8 years ago

So something is wrong idk what no errors because i cant test in studio.

Saving not working and loading. And the other stats are not showing up.

Does someone know what i did wrong? Thanks

Full script:

levelKey = "PlayerLevel"
exppKey = "PlayerExp"
wiKey = "PlayerWi"
loKey = "PlayerLo"
moKey = "PlayerMo"
coKey = "PlayerCo"
troKey = "PlayerTro"
geKey = "PlayerGe"
local maxlevel = 250

game.Players.PlayerAdded:connect(function(player)
    if player:WaitForDataReady() then
        local stats = Instance.new("IntValue", player) 
        stats.Name = "leaderstats"
        local level = Instance.new("IntValue", stats) 
        level.Name = "Level" 
        level.Value = 1
        level.Value = player:LoadNumber(levelKey)
        local expp = Instance.new("IntValue", stats) 
        expp.Name = "XOP"
        expp.Value = player:LoadNumber(exppKey)
        expp.Value = 0 while wait() 
        do local extralevel = level.Value 
            local expneed = ((extralevel * 2) - 1) * 50 
            if level.Value < maxlevel then 
                if expp.Value >= expneed then level.Value = level.Value + 1 
                    expp.Value = expp.Value - expneed 
                end 
            end 
        end
        local win = Instance.new('IntValue', stats)
        win.Name = "QW" -- Wins (Dd)
        win.Value = 0
        win.Value = player:LoadNumber(wiKey)
        local lose = Instance.new('IntValue', stats)
        lose.Name = "LP" -- Loses (De)
        lose.Value = 0
        lose.Value = player:LoadNumber(loKey)
        local money = Instance.new('IntValue', stats)
        money.Name = "DHJK" -- Money (Df)
        money.Value = 0
        money.Value = player:LoadNumber(moKey)
        local coin = Instance.new('IntValue', stats)
        coin.Name = "IPE" -- Coins (Dg)
        coin.Value = 0
        coin.Value = player:LoadNumber(coKey)
        local trofee = Instance.new('IntValue', stats)
        trofee.Name = "TR" -- Trofee (Dh)
        trofee.Value = 0
        trofee.Value = player:LoadNumber(troKey)
        local ge = Instance.new('IntValue', stats)
        ge.Name = "KLOPT" -- Gems (Di)
        ge.Value = 0
        ge.Value = player:LoadNumber(geKey)
    end
end) 

game.Players.PlayerRemoving:connect(function(player) 
    if player:FindFirstChild("leaderstats") then
        player:SaveNumber(levelKey, player.leaderstats.level.Value)
        player:SaveNumber(exppKey, player.leaderstats.expp.Value)
        player:SaveNumber(wiKey, player.leaderstats.win.Value)
        player:SaveNumber(loKey, player.leaderstats.lose.Value) 
        player:SaveNumber(moKey, player.leaderstats.money.Value) 
        player:SaveNumber(coKey, player.leaderstats.coin.Value) 
        player:SaveNumber(troKey, player.leaderstats.trofee.Value) 
        player:SaveNumber(geKey, player.leaderstats.ge.Value)     
    end
end)

Edit*

0
I did read the wiki article, but I don't see whats wrong I hope someone find the problem. minetrackmania 186 — 8y
1
Why did u make all of the keys the same... wazap 100 — 8y
0
But even if i change the keys it doesnot work. minetrackmania 186 — 8y
0
Also your saving wont work since you dont have player.leaderstats.level.Value, player.leaderstats.expp.Value, and so on. All you have based on your script are player.leaderstats.QW.Value and etc since these directories are based off of the name wazap 100 — 8y
0
Well whats better to save and load ? When a server shut down. Datastore or this? minetrackmania 186 — 8y

Answer this question