It seems to me that you don't currently have a leaderboard. Try using this.
First, let's create a Script in the Workspace and name it 'Stats'. Once we've done that, we can begin.
We'll begin with defining our leaderboard values. We'll use a nested array..
local boardStats = {
{ "IntValue", "Money" }
}
Now that we have some values to play with, we'll need our function to usher our leaderboard into existence.
function LeaderBoard(player)
local leaderstats = Instance.new("IntValue", player)
leaderstats.Name = "leaderstats"
end
This will make the leaderboard visible in the PlayerList. Now we need to add our leaderboard values. To do this, we will use a for loop.
function LeaderBoard(player)
local leaderstats = Instance.new("IntValue", player)
leaderstats.Name = "leaderstats"
for n in pairs(boardStats) do
local stat = Instance.new(boardStats[n][1], leaderstats)
stat.Name = boardStats[n][2]
end
end
With this for loop, we're traversing the boardStats array, one nested array at a time. We come through the first time, and we'll find that boardStats[1] is equal to { "IntValue", "Money" } and we need to separate these. So we create an instance of boardStats[n][1] and place it into leaderstats. Once we've done that, we name the instance boardStats[n][2].
Last but not least, we need to connect the PlayerAdded function to get this to add values to every new player.
game:GetService("Players").PlayerAdded:connect(LeaderBoard)
Once that's done, altogether we have our leaderboard!
local boardStats = {
{ "IntValue", "Money" }
}
function LeaderBoard(player)
local leaderstats = Instance.new("IntValue", player)
leaderstats.Name = "leaderstats"
for n in pairs(boardStats) do
local stat = Instance.new(boardStats[n][1], leaderstats)
stat.Name = boardStats[n][2]
end
end
game:GetService("Players").PlayerAdded:connect(LeaderBoard)
Your button should then be able to function.
2 comments
I think take away the word "name" before "keaderstats"
do game.Players:FindFirstChild(name)