I am attempting to make a global leaderboard and my leaderboard works fine but for some reason when I print out one of my ordered data store keys it prints out -2 instead of an actual userId even though I set the key correctly. Here is my current code.
local Leaderboards = {}
local DataStoreService = game:GetService("DataStoreService")
local ProfileController = require(script.Parent.ProfileController)
local MathUtil = require(game:GetService("ReplicatedStorage"):WaitForChild("Utilities").MathUtil)
local CoinsStore = DataStoreService:GetOrderedDataStore("CoinStore")
local RebirthStore = DataStoreService:GetOrderedDataStore("RebirthStore")
function Leaderboards:UpdateLeaderboards()
local CoinsPage
local RebirthPage
for _,player in pairs(game.Players:GetPlayers()) do
pcall(function()
local ProfileController = ProfileController:getProfileManager(player)
CoinsStore:SetAsync(player.UserId, MathUtil.compress(ProfileController:getStat("TotalCoins", "PlayerStats")))
RebirthStore:SetAsync(player.UserId, MathUtil.compress(ProfileController:getStat("Rebirths", "PlayerStats")))
end)
end
wait(15)
local success, err = pcall(function()
local pages = CoinsStore:GetSortedAsync(false, 25)
CoinsPage = pages:GetCurrentPage()
pages = RebirthStore:GetSortedAsync(false, 25)
RebirthPage = pages:GetCurrentPage()
end)
if not success then
error(err)
end
for _,v in pairs(workspace.Leaderboards.Coins:GetChildren()) do
for _,v in pairs(v.UIPart.SurfaceGui.Main:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
end
for _,v in pairs(workspace.Leaderboards.Rebirths:GetChildren()) do
for _,v in pairs(v.UIPart.SurfaceGui.Main:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
end
for rank, data in ipairs(CoinsPage) do
for _,v in pairs(workspace.Leaderboards.Coins:GetChildren()) do
local PlayerTemplate = game:GetService("ServerStorage").UIElements.Leaderboards.PlayerTemplate:Clone()
PlayerTemplate.Parent = v.UIPart.SurfaceGui.Main
local success, err = pcall(function()
print(data.key)
PlayerTemplate.PlayerName.Text = game.Players:GetNameFromUserIdAsync(data.key)
PlayerTemplate.Rank.Text = "#"..rank
PlayerTemplate.Amount.Text = MathUtil.Abbreviate(MathUtil.Decompress(data.value))
local content, isReady = game.Players:GetUserThumbnailAsync(data.key, Enum.ThumbnailType.AvatarThumbnail, Enum.ThumbnailSize.Size420x420)
PlayerTemplate.PlayerIcon.Image = content
end)
if not success then
error(err)
end
end
end
for rank, data in ipairs(RebirthPage) do
for _,v in pairs(workspace.Leaderboards.Rebirths:GetChildren()) do
local PlayerTemplate = game:GetService("ServerStorage").UIElements.Leaderboards.PlayerTemplate:Clone()
PlayerTemplate.Parent = v.UIPart.SurfaceGui.Main
local success, err = pcall(function()
PlayerTemplate.PlayerName.Text = game.Players:GetNameFromUserIdAsync(data.key)
PlayerTemplate.Rank.Text = "#"..rank
PlayerTemplate.Amount.Text = MathUtil.Abbreviate(MathUtil.Decompress(data.value))
local content, isReady = game.Players:GetUserThumbnailAsync(data.key, Enum.ThumbnailType.AvatarThumbnail, Enum.ThumbnailSize.Size420x420)
PlayerTemplate.PlayerIcon.Image = content
end)
if not success then
error(err)
end
end
end
end
return Leaderboards
Here is my output wich you can see its printing -2.
My first thought is that the id is the userid’s for Player1 and Player2 when I use a test server but want to make sure so Im not forgetting anything.