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

Help with a leaderboard?

Asked by 9 years ago
game.Workspace.PlayerAdded(function(player)
    local stats = Instance.new("IntValue", player)
    stats.Name = "leaderstats"

    local points = Instance.new("IntValue", player.leaderstats)
    points.Name = "Points"

    local wins = Instance.new("IntValue", player.leaderstats)
    wins.Name = "Wins"


end)

What in the world is the problem? Basically, what the script does is load an IntValue and creates a leaderboard. It's not working, but I don't receive an error about WHY it doesn't work.

2 answers

Log in to vote
0
Answered by
P100D 590 Moderation Voter
9 years ago

You haven't initialized leaderstats, and you're calling PlayerAdded on the wrong service. Your code should look like this:

game.Players.PlayerAdded:connect(function(player)
    --PlayerAdded is for game.Players, not game.Workspace.

     --Initialize the leaderstats model in the player
    local leaderstats = Instance.new("Model", player)
    leaderstats.Name = "leaderstats"

    --Initialize a leaderboard value
    local pts = Instance.new("IntValue", leaderstats)
    pts.Name = "Points"
    pts.Value = "0" --Set default value, data persistence overrides this.
end
Ad
Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

PlayerAdded isn't associated with Workspace, but with the Players service instead. I don't believe parenting stats to the character would display them on the leaderboard.

Answer this question