What's this error and how do I fix it? (Global leaderboards)

I’ve made global leaderboards in my game, I have two: one for money and another for levels. I made the money one first, it seemed to be working fine, I copy pasted and edited one for levels, it’s working fine, but the money one now errors with this:

Players.GetNameFromUserId() failed because HTTP 404 (NotFound)

What does it mean and how do I fix it? (The levels leaderboard is identical and works fine)

To Use GetNameFromUserId() you have to say
Players:GetNameFromUserId() so instead of the . do :

1 Like

I am doing that, doesn’t work.

Could you post your script here please?

1 Like

How do I post scripts with proper formatting?

To post it proper formatting use ``` so it acutally shows as a code

1 Like

Thanks, didn’t know that. Here it is:

local moneyLeaderboard = dataStoreService:GetOrderedDataStore("moneyLeaderboard")
local levelLeaderboard = dataStoreService:GetOrderedDataStore("levelLeaderboard")

local function updateLevelLeaderboard()
	local success, errorMessage = pcall(function()
		local data = levelLeaderboard:GetSortedAsync(false, 10)
		local levelPage = data:GetCurrentPage()
		for rank, data in ipairs(levelPage) do
			local username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = username
			local level = data.value
			local isOnLeaderboard = false
			for i, v in pairs(game.Workspace.Map.Important.Leaderboards.levelsLeaderboard.Main.Background:GetChildren()) do
				if v.name then
					if v.name.Text == Name then
						isOnLeaderboard = true
						break
					end
				end
			end
			
			if level and isOnLeaderboard == false then
				local newFrame = game.ReplicatedStorage:WaitForChild("globalLeaderboards"):WaitForChild("leaderboardFrame"):Clone()
				newFrame.name.Text = Name
				newFrame.score.Text = level
				newFrame.position.Text = rank
				newFrame.Parent = game.Workspace.Map.Important.Leaderboards.levelsLeaderboard.Main.Background
			end
		end
	end)
	if not success then
		print(errorMessage)
	end
end

local function updateMoneyLeaderboard()
	local success, errorMessage = pcall(function()
		local data = moneyLeaderboard:GetSortedAsync(false, 10)
		local moneyPage = data:GetCurrentPage()
		for rank, data in ipairs(moneyPage) do
			local username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
			local Name = username
			local money = data.value
			local isOnLeaderboard = false
			for i, v in pairs(game.Workspace.Map.Important.Leaderboards.moneyLeaderboard.Main.Background:GetChildren()) do
				if v.name then
					if v.name.Text == Name then
						isOnLeaderboard = true
						break
					end
				end
			end
			
			if money and isOnLeaderboard == false then
				local newFrame = game.ReplicatedStorage:WaitForChild("globalLeaderboards"):WaitForChild("leaderboardFrame"):Clone()
				newFrame.name.Text = Name
				newFrame.score.Text = money
				newFrame.position.Text = rank
				newFrame.Parent = game.Workspace.Map.Important.Leaderboards.moneyLeaderboard.Main.Background
			end
		end
	end)
	if not success then
		print(errorMessage)
	end
end

while true do
	for _, player in pairs(game.Players:GetPlayers()) do
		levelLeaderboard:SetAsync(player.UserId, player.Stats.Level.Value)
	end

	for _, frame in pairs(game.Workspace.Map.Important.Leaderboards.moneyLeaderboard.Main.Background:GetChildren()) do
		if frame.Name == "leaderboardFrame" then
			frame:Destroy()
		end
	end
	
	for _, frame in pairs(game.Workspace.Map.Important.Leaderboards.levelsLeaderboard.Main.Background:GetChildren()) do
		if frame.Name == "leaderboardFrame" then
			frame:Destroy()
		end
	end

	
	updateLevelLeaderboard()
	print("Level leaderboard updated")
	updateMoneyLeaderboard()
	print("Money leaderboard updated")
	wait(60)
end

Try printing data.key, if it’s not a UserId then that’s most likely the issue.

1 Like

Your error is an error from Players Service, this is an internal error caused by Roblox’s current outage. This should work fine when the outage has been fixed.

1 Like

How come the other leaderboard works though? The scripts are identical.

When your trying to game.Players:GetNameFromUserIdAsync(tonumber(data.key)) then

data.key is nil

This shows you that quhequ is nil

local quhequ = "Data_271040226"
print(tonumber(quhequ))
local username = game.Players:GetNameFromUserIdAsync(tonumber(quhequ))
print(username)

Output: image

1 Like

The web call must’ve failed when that script called :GetNameFromUserIdAsync() Theoretically, your script should work if you run it again.

1 Like

I’ve run it a million times already, it’s always the money leaderboard that errors, and the level one works perfectly fine.

Ah, I just did what ProspektNova suggested above, and it prints “-1” from updateMoneyLeaderboard(), but it prints what looks like a user id from updateLevelLeaderboard()

DataStores are having tons of issues right now, so that could honestly be your problem too. The global leaderboards in my game Admin Heaven, arent working at the moment either.

1 Like

I just ran some tests and your error is not actually caused by the current outage. Yes, the -1 user id is the issue. I’d also suggest wrapping that function in a pcall since it’s a webcall just in case it will get affected by outages.

Edit:
HTTP 404 (NotFound) is caused by user IDs that do not have a valid Roblox user either due to account deletion or user doesn’t exist yet.

1 Like

Do you reckon testing the leaderboards on a local server did something to cause this? If I recall correctly, when I started a local server with 3 players, the leaderboards broke (since the players don’t actually have user id’s)

Doing Local Studio tests (like 3 player studio tests) you’d have Player1, Player2, and Player3. Their ids would be -1, -2, and -3. If they were added to the store, when trying to convert their ids to usernames it would error. Make sure before running SetAsync that the ids are > 0, along with wrapping the GetNAmeFromUserIdAsync in a pcall.

1 Like

This is correct. Since test sessions do not use actual players, their user IDs do not point to actual Roblox users, hence “Not Found” in the error message.

@At0micTac0
You can also use RunService.IsStudio to help mitigate the issue.

1 Like

What do I do to fix this though? I did what kingjohnthewinner suggested.