I've made a leaderboard in my game and when I published it and played on my alt it says on the Console: "Players:GetNameFromUserId() failed because HTTP 404 (NotFound)". How to fix the error? I've allowed HTTP requests and API services. Here's the script
local DataStoreService = game:GetService("DataStoreService")
local GemsLeaderboard = DataStoreService:GetOrderedDataStore("GemLeaderboard")
local LastPosition = UDim2.new(0.5,0,0.05,0)
local Leaderboard = workspace.Lands.Forest.GlobalLeaderboard.LeaderboardGui.Holder
function UpdateLeaderboard()
local Success
local ErrorMessage
for i = 1,5 do
Success,ErrorMessage = pcall(function() -- sometimes errors like the HTTP error code 404 might occur. If that happens it wont break the entire script bc the main is wrapped in a pcall
local Data = GemsLeaderboard:GetSortedAsync(false, 5)
local GemsPage = Data:GetCurrentPage()
for Rank, data in ipairs(GemsPage) do
local userName = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local Name = userName
local Gems = data.value
local Included = false
for i, v in pairs(Leaderboard:GetChildren()) do
if v.Player.Text == Name then
Included = true
break
end
end
if Gems and not Included then
local Template = game.ServerStorage.LeaderboardTemplate:Clone()
Template.Player.Text = Name
Template.Rank.Text = Rank
Template.Parent = Leaderboard
local Modified = Gems
local UnModified
while true do
Modified,UnModified = string.gsub(Modified,"^(-?%d+)(%d%d%d)", "%1,%2")
if (UnModified == 0) then
break
end
end
Template.Gems.Text = Modified
if #Leaderboard:GetChildren() == 1 then
Template.Position = LastPosition
LastPosition = UDim2.new(0.5,0,0.05,0)
else
Template.Position = UDim2.new(0.5,0,LastPosition.Y.Scale + 0.10,0)
LastPosition = UDim2.new(0.5,0,LastPosition.Y.Scale + 0.10,0)
end
end
end
end)
if ErrorMessage then wait(1) else break end
end
if not Success then
print(ErrorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
GemsLeaderboard:SetAsync(player.UserId, player.Leaderstats.Gems.Value)
end
for _, frame in pairs (Leaderboard:GetChildren()) do
frame:Destroy()
end
UpdateLeaderboard()
print("Leaderboard Updated!")
wait(60)
end
