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