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)
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
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.
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.
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.
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.
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.