Global Leaderboards Are Acting Up *HELP!*

How would I do that without messing the whole script?

1 Like
local DataStoreService2 = game:GetService("DataStoreService")
local CoinsLeaderboard = DataStoreService2:GetOrderedDataStore("CoinsLeaderboard")

local function updateLeaderboard()
        -- local success, errorMessage = pcall (function()
                local Data = CoinsLeaderboard:GetSortedAsync(false, 10)
                local CoinsPage = Data:GetCurrentPage()
                for Rank, data in ipairs(CoinsPage) do
                       local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
                       local Name = userName
                       local Coins = data.value
                       local isOnLeaderboard = false
                       for i, v in pairs(game.Workspace.Lobby.Leaderboard.GlobalLeaderboard2.LeaderboardGUI2.Holder:GetChildren()) do
                             if v.Player.Text == Name then
                                  isOnLeaderboard = true
                                  break
                           end
                    end

                     if Coins and isOnLeaderboard == false then
                            local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame2"):Clone()
                            newLbFrame.Player.Text = Name
                            newLbFrame.Coins.Text = Coins 
                            newLbFrame.Rank.Text = "#"..Rank
                            newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.Lobby.Leaderboard.GlobalLeaderboard2.LeaderboardGUI2.Holder:GetChildren()), 0)
                            newLbFrame.Parent = game.Workspace.Lobby.Leaderboard.GlobalLeaderboard.LeaderboardGUI.Holder
                     end
              end
      -- end)

      -- if not success then
            -- print(errorMessage)
      -- end
end

while true do

        for _, player in pairs(game.Players:GetPlayers()) do
              CoinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Coins.Value)
        end

        for _, frame in pairs (game.Workspace.Lobby.Leaderboard.GlobalLeaderboard2.LeaderboardGUI2.Holder:GetChildren()) do
              frame:Destroy()
        end

        updateLeaderboard()
        print("Updated!")

        wait(10)
end

Just comment those parts I did and click the error and say what that line says.

1 Like

Line 9, error is this
[Players:GetNameFromUserId() failed because HTTP 404 (NotFound)] @BuilderDolphin

1 Like

That is odd since the method is GetNameFromUserIdAsync() and it is outputting GetNameFromUserId() only. Can you make it so it prints tonumber(data.key)? What does it say?

2 Likes

Ohh, considering it’s a ordered leaderboard, perhaps your userId is in the negatives.

2 Likes

What does that mean? 30 characters

Were you able to make it so it prints the key?

1 Like

Not yet, but I don’t understand why it doesn’t work when the other does:


Ignore whats happening with the leaderboard on the left XD, it only happens in studio for some reason

1 Like

Wait, add back the pcall() and anything commented out and make it do print(tonumber(data.key))

1 Like

This happened to me. The reason this happened is you probably made a local server in studio where the players’ names are Player1 and Player2. The reason it did not work is because the user ids of these players are -1 and -2 so the script errored there. To fix this, just change the name of the ordered datastore. This means that whoever was on the leaderboard previously has to join again for their name to get on it.

2 Likes

yep, like I said, getNameFromUserId is a web call, and any web call has the potential to fail unexpectedly. That’s why it important to wrap it in a pcall

2 Likes

It printed a number 1423115391

1 Like

That is your user id…Check on my previous reply.

1 Like

You can also make it check if the key is greater than 0 to prevent bugs like @TheDragonSlayer5481 said

3 Likes

If you do not want to get complicated as I could tell that you are not that experienced as you copied TheDevKing’s (@UseCode_Tap)vid on it, try my method I stated before in my previous replies. Reply if my method works or not, so we can know if we have to help you even more.

1 Like

I changed the name of the ordered data store- but now my coins value shows up on the wins leaderboard?

1 Like

Change the name of both of the data stores:
this part,

local CoinsLeaderboard = DataStoreService2:GetOrderedDataStore("CoinsLeaderboard")

Just add like a 1 to the end.

1 Like

You are an absolute life saver guys! Thanks for all your help!

1 Like

Happy I was able to help :grin: To not let this happen again, do not go into a big project as a beginner. Watch TheDevKing’s and AlvinBloxx’s tutorials , both beginner and advanced. Also, change up your surface gui on the leaderboard. To be honest, it is a bit ugly :sweat_smile:

1 Like

These are mine for example, I also used TheDevKing’s tutorial on it:

2 Likes