Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

what is PlayerScore in data persistence?

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

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.

1 comment

0

oh okay thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.