I created a global leaderboard that uses an ordered data store to display the top 25 players, the problem I have is that the players sometimes cannot be found.
Is there a way to delete such players from the ordered data store?
Here is the following code for creating a global leaderboard depending on the player’s level:
local dss = game:GetService("DataStoreService")
local data = dss:GetOrderedDataStore("DataTest02")
local storedDataName = "Level"
local event = game:GetService("ReplicatedStorage"):WaitForChild("Leaderboard")
wait(5)
while true do
for i, player in pairs(game.Players:GetPlayers()) do
local exp = player:FindFirstChild("Experience")
if exp then
local levels = exp.Level
if levels then
pcall(function()
data:UpdateAsync(player.UserId,function(oldVal)
return levels.Value
end)
end)
end
end
end
local pages = data:GetSortedAsync(false, 25)
local top = pages:GetCurrentPage()
local datatab = {}
local on = 1
for i, data in ipairs(top) do
local userid = data.key
local level = data.value
local name = "Loading..."
local s, e = pcall(function()
name = game.Players:GetNameFromUserIdAsync(userid)
end)
if not s then
warn("Erros getting name for ".. userid .. ". Error: ".. e)
end
local image = "https://www.roblox.com/headshot-thumbnail/image?userId=" .. userid .. "&width=150&height=150&format=png"
datatab[on] = {
["Name"] = name,
["Image"] = image,
["Wins"] = level
}
on = on + 1
end
event:FireAllClients(datatab)
wait(10)
end