I do not understand this error

I have three global leaderboards one is working fine which is the first function in the script below. I got this error like three times and the other two leaderboards do not work. Players.GetNameFromUserId() failed because HTTP 404 (NotFound). This only happened after I made a local server with three players in the studio. Before that, the leaderboards were working fine.Here is the script:

 local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("ObbyData")
local WinsLeaderboard1 = DataStoreService:GetOrderedDataStore("AvgDStore")
local WinsLeaderboard2 = DataStoreService:GetOrderedDataStore("ObbyDatas")

local function updateLeaderboard()
        local success, errorMessage = pcall (function()
                local Data =WinsLeaderboard:GetSortedAsync(false, 5)
                local WinsPage = Data:GetCurrentPage()
                for Rank, data in ipairs(WinsPage) do
			                       local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			
                       local Name = userName
                       local Seconds = data.value
                       local isOnLeaderboard = false
                       for i, v in pairs(game.Workspace.Locations.Leaderboardarea.LeaderboardArea.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
                             if v.Name2.Text == Name then
                                  isOnLeaderboard = true
                                  break
                           end
                    end

                     if Seconds and isOnLeaderboard == false then
                            local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
                            newLbFrame.Name2.Text = Name
                            newLbFrame.TimeSpent.Text = Seconds
                            newLbFrame.Rank.Text = "#"..Rank
                            newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.008 * #game.Workspace.Locations.Leaderboardarea.LeaderboardArea.Leaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
				                            newLbFrame.Parent = game.Workspace.Locations.Leaderboardarea.LeaderboardArea.Leaderboard.LeaderboardGUI.Holder 
				
                     end
              end
      end)

      if not success then
            print(errorMessage)
      end
end
local function updateLeaderboard1()
	
        local success, errorMessage = pcall (function()
                local Data =WinsLeaderboard1:GetSortedAsync(true, 5)
                local WinsPage = Data:GetCurrentPage()
                for Rank, data in ipairs(WinsPage) do
                       local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
                       local Name = userName
			                       local AvgD = data.value
		
                       local isOnLeaderboard = false
                       for i, v in pairs(game.Workspace.Locations.Leaderboardarea.LeaderboardArea3.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
                             if v.Name2.Text == Name then
                                  isOnLeaderboard = true
                                  break
                           end
                    end

                     if AvgD and isOnLeaderboard == false then
                            local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
                            newLbFrame.Name2.Text = Name
                            newLbFrame.TimeSpent.Text = AvgD 
                            newLbFrame.Rank.Text = "#"..Rank
                            newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.008 * #game.Workspace.Locations.Leaderboardarea.LeaderboardArea3.Leaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
                            newLbFrame.Parent = game.Workspace.Locations.Leaderboardarea.LeaderboardArea3.Leaderboard.LeaderboardGUI.Holder 
                     end 
			              end
			
		      end)
		

      if not success then
            print(errorMessage)
      end
end
local function updateLeaderboard2()
        local success, errorMessage = pcall (function()
                local Data =WinsLeaderboard2:GetSortedAsync(true, 5)
                local WinsPage = Data:GetCurrentPage()
                for Rank, data in ipairs(WinsPage) do
                       local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
                       local Name = userName
                       local Deaths = data.value
                       local isOnLeaderboard = false
                       for i, v in pairs(game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
                             if v.Name2.Text == Name then
                                  isOnLeaderboard = true
                                  break
                           end
                    end

                     if Deaths and isOnLeaderboard == false then
                            local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
                            newLbFrame.Name2.Text = Name
                            newLbFrame.TimeSpent.Text = Deaths
                            newLbFrame.Rank.Text = "#"..Rank
                            newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.008 * #game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
                            newLbFrame.Parent = game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder 
                     end
              end
      end)

      if not success then
            print(errorMessage)
      end
end
local g =0
wait(8)
while true do

	        for _, player in pairs(game.Players:GetPlayers()) do
		local Avg =  math.floor(player.leaderstats["Avg Deaths"].Value + 0.5)
		              WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Seconds.Value)
		WinsLeaderboard2:SetAsync(player.UserId, player.leaderstats.Deaths.Value)
		WinsLeaderboard1:SetAsync(player.UserId, Avg)
        end

        for _, frame in pairs (game.Workspace.Locations.Leaderboardarea.LeaderboardArea.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
              frame:Destroy()
	        end
	
        for _, frame in pairs (game.Workspace.Locations.Leaderboardarea.LeaderboardArea2.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
              frame:Destroy()
	        end
	for _, frame in pairs (game.Workspace.Locations.Leaderboardarea.LeaderboardArea3.Leaderboard.LeaderboardGUI.Holder:GetChildren()) do
              frame:Destroy()
	        end
        updateLeaderboard()
	updateLeaderboard1()
	updateLeaderboard2()	 
       
	g = g+1
	        print("Updated Seconds,Deaths and Average Deaths Leaderboards!",g)


        wait(60)
end	

	
	
	
	
	
1 Like

It’s an error telling you that something is missing / the link is wrong. Also what line was the stack tracing it to?

2 Likes

I know that as local players user ids are -1,-2 and -3 but how would I fix this problem. I tried using this but it is confusing: What's this error and how do I fix it? (Global leaderboards)

Not any line as it printed the error message so it went to the line where it prints the message.

What line is it on? Show me the stack trace

1 Like


This is the stack:

1 Like

Change this to GetNameFromUserIdAsync

1 Like

it is:

   local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))

Data.key is possibly nil, before just print the type of it to check if it’s nil

1 Like

Capture2

Try testing it in an Open client instead of studio, because -1 isn’t a valid userid

2 Likes

The four at the top were from the working leaaderboard.

That is the user id of a local player in a test server.

In a normal server, nothing happens, the two leader boards do not work and the data keys or error messages are not being printed.

And it’s attempting to find that UserID that doesn’t exist on the friends.roblox.com site, so you need to test with actual accounts

1 Like

I am testing with my own account in a normal server.

print(game.Players:GetNameFromUserIdAsync(-1))

returns Players:GetNameFromUserId() failed because HTTP 404 (NotFound) because it cannot find a player with this Id

1 Like

So what do i do, should i put that print in below the data key print

No, like I said before, test on an open client and not on Studio

1 Like