I just recently really tried to start scripting and I've run into a problem with a global stats leaderboard. The problem is that I made a local server and tried to use the leaderboard with them and there user Id's are negative numbers (eg: -1 -2 -3) which the script can't use. I've seen some other people with this problem but I'm still unsure of how to fix it. My script is below if you want to look it over. Does anyone have an in-depth fix for this problem?
local DataStoreService = game:GetService("DataStoreService")
local WinsLeaderboard = DataStoreService:GetOrderedDataStore("WinsLeaderboard")
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:GetUserIdFromNameAsync(tonumber(data.key))
local Name = userName
local Wins = data.value
local isOnLeaderboard = false
for i, v in pairs(game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
if v.Player.Text == Name then
isOnLeaderboard = true
break
end
end
if Wins and isOnLeaderboard == false then
local newLbFrame = game.ReplicatedStorage:WaitForChild("LeaderboardFrame"):Clone()
newLbFrame.Player.Text = Name
newLbFrame.Wins.Text = Wins
newLbFrame.Rank.Text = "#"..Rank
newLbFrame.Position = UDim2.new(0, 0, newLbFrame.Position.Y.Scale + (.08 * #game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()), 0)
newLbFrame.Parent = game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder
end
end
end)
if not success then
print(errorMessage)
end
end
while true do
for _, player in pairs(game.Players:GetPlayers()) do
WinsLeaderboard:SetAsync(player.UserId, player.leaderstats.Wins.Value)
end
for _, frame in pairs (game.Workspace.GlobalLeaderboard.LeaderboardGUI.Holder:GetChildren()) do
frame:Destroy()
end
updateLeaderboard()
print("Updated!")
wait(10)
end

2 comments
I'm not quite sure if I understand your problem, but if I do then what I would suggest is that you use a "pcall" function.
I'm using a pcall. My problem is that it's saved the data of the players from a local server which it can't use because they aren't proper ids and I'm wondering how to get rid of them. Or how to clear the leader board data