I’ve been trying to make a basic leaderboard system using ordered data stores and it works fine except for when it wants to display my kills (an integer). If I convert it to a string, It becomes nil
. Im using the following function to do this:
local function updateLeaderBoard()
local success, pages = pcall(function()
local pages = killDataStore:GetSortedAsync(false, 10)
local killsPage = pages:GetCurrentPage()
for rank, data in ipairs(killsPage) do
--Player Data
local username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local kills = data.Value -- this is the problem
local isOnLeaderBoard = false
-- Check for leaderboard
for i,v in pairs(script.Parent.Holder:GetChildren()) do
if v.Player.Text == username then
isOnLeaderBoard = true
break
end
end
-- Apply stats to leaderboard
if not isOnLeaderBoard then
local playerLeaderBoard = game.ReplicatedStorage:WaitForChild("RankPlayer"):Clone()
playerLeaderBoard.Player.Text = username
playerLeaderBoard.Rank.Text = rank
playerLeaderBoard.Kills.Text = data.Value -- The problem is here as well
playerLeaderBoard.Parent = script.Parent:FindFirstAncestor("LeaderPart").SurfaceGui.Holder
end
end
end)
end
The leaderstat containing kills is an int value and this is what the function is updating:
if i change the value of kills to a placeholder such as “kills” It works fine. Using the following loop:
for _, player in pairs(game.Players:GetPlayers()) do
killDataStore:SetAsync(player.UserId, player.leaderstats.Kills.Value)
print("Saved player with".. player.leaderstats.Kills.Value .. "Kills")
end
Also works fine printing the correct value. It has to be a problem with the datastore but I have no clue what. Please help.