hello there, i’ve recently trying to do a leaderboard for my game using GetOrderedDataStore()
to organize the leaderboard, the problem is that when i try to get the data from GetOrderedDataStore()
with a for loop it doesn’t run (i asume that it doesn’t get any data since it doesn’t throw any errors and it doesn’t print anything that is on the for loop, proving that it isn’t running), and yes, i already have data saved on the datastore that i’m trying to get on the leaderboard (btw the data is a single-value number that is positive), so let me show you the code:
local level = dss:GetOrderedDataStore("level")
local function leaderboard()
local success,errormessage = pcall(function()
local data = level:GetSortedAsync(false,10)
local levelpage = data:GetCurrentPage()
for r, d in ipairs(levelpage) do
print(d.Value)
local username = game.Players:GetNameFromUserIdAsync(tonumber(data.key))
local level = d.Value
local isonleaderboard = false
for i,v in pairs(holder:GetChildren()) do
if v:IsA("Frame") then
if v.Player.Text == username then
isonleaderboard = true
break
end
end
end
if level < 1 and isonleaderboard == false then
local newframe = rankframe:Clone()
newframe.Player.Text = username
newframe.Rank.Text = r
newframe.Level.Text = level
newframe.Parent = holder
end
end
end)
if not success then
error(errormessage)
end
end
also i’m saving the data like this:
game.Players.PlayerRemoving:Connect(function(player)
local userid = player.UserId
local success, errormessage = pcall(function()
level:SetAsync(userid,player.leaderstats.Level.Value)
end)
if not success then
error(errormessage)
else
print("saved")
end
end)
thanks for all the people that could help!
EDIT: the saving and the leaderboard codes are on separated scripts, and the saving one saves a GetDataStore()
, not the actual GetOrderedDataStore("level")
that im using on the first code