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

what is PlayerScore in data persistence?

Asked by
Prioxis 673 Moderation Voter
9 years ago

So i'm going by the Roblox Wiki page (which isn't very descriptive on everything) but in this line of code

scoreKey = "PlayerScore"

game.Players.PlayerAdded:connect(function(player)
    if player:WaitForDataReady() then
        -- create leaderboard
        local ls = Instance.new("IntValue")
        ls.Name = "leaderstats"
        ls.Parent = player

        --create the score stat
        local score = Instance.new("IntValue")
        score.Name = "Score"
        score.Parent = ls
        score.Value = player:LoadNumber(scoreKey)
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    if player:FindFirstChild("leaderstats") then
        player:SaveNumber(scoreKey, player.leaderstats.Score.Value)    
    end
end)

theres a variable named scoreKey = "PlayerScore"

what does scoreKey do for data persistence if anything at all? and does it need to be changed based off of the leaderstat??

Because I see that the leaderstat is named "Score". Do I change "PlayerScore" to "PlayerGold?" for my leaderstat which is "Gold"

1 answer

Log in to vote
0
Answered by 9 years ago

No, unless you're making several values, although you should change it anyway as that's what its being saved as. Also, you really should consider using DataStore instead.

0
oh okay thank you! Prioxis 673 — 9y
Ad

Answer this question