Hello devs!
I am currently scripting a global leaderboard for my game. But there is one big problem: As far as I know, “:GetSortedAsync (false, 50)” will indicate the 50 highest values in the datastore. But for some reason only one value is output. Here is the script:
local ds = game:GetService("DataStoreService")
local coinsODS = ds:GetOrderedDataStore("JumpSaveSystem")
local timeUntilReset = 10
while wait(1) do
timeUntilReset = timeUntilReset - 1
script.Parent.Parent.ResetTime.Text = "Resetting in " .. timeUntilReset .. " seconds..."
if timeUntilReset == 0 then
timeUntilReset = 10
for i, plr in pairs(game.Players:GetPlayers()) do
coinsODS:SetAsync(plr.UserId, plr.leaderstats.Jumps.Value)
end
for i, leaderboardRank in pairs(script.Parent:GetChildren()) do
if leaderboardRank.ClassName == "Frame" then
leaderboardRank:Destroy()
end
end
local success, errorMsg = pcall(function()
local data = coinsODS:GetSortedAsync(false, 50)
local coinsPage = data:GetCurrentPage()
for rankInLB, dataStored in ipairs(coinsPage) do
local name = game.Players:GetNameFromUserIdAsync(tonumber(dataStored.key))
local coins = dataStored.value
local template = script.Template:Clone()
template.Name = name .. "Leaderboard"
template.PlrName.Text = name
template.Rank.Text = "#" .. rankInLB
template.Coins.Text = coins
template.Parent = script.Parent
end
end)
end
end
335/5000
In the “for rankInLB, dataStored in ipairs (coinsPage) do” loop, all values are processed, but only one persons data was cloned on the leaderboard. does anyone have any idea what could be the error here. (Incidentally, there are well over 10 million strings stored in the datastore, so there are definitely not too few)
Ah okay. Like Quwanterz said, if only you have played when the datastore was put into place, only you will show up on the leaderboard. I’m not too sure about the circumstances around this, but do you happen to be the only one on the leaderboard that is showing up?
I am aware of that. The datastore has been in my game for months (and it was online). It works as it should. It saves and loads all data correctly. I fear that the problem lies elsewhere.
Hmm, I think you might be misunderstanding the ordered data store incorrectly, but if you aren’t then ignore this.
So, you might be implementing a global leaderboard in your game during this time, so you went and created an ordered data store. I think you are thinking that when you get “JumpSaveSystem” you are getting the datastore that currently saves all the data in your game. The difference here is that there is no ordered data store in your game with the name of “JumpSaveSystem”, so when you did local coinsODS = ds:GetOrderedDataStore("JumpSaveSystem") it created a new one with that name.
You can’t get the values from the global data store, and try to use getordereddatastore on it, because it is not an ordered data store. Now if all of what I’m saying is correct so far, the reason it is only showing one value, which I presume is yours, is because you are the only one with data saved to the ordered data store. When you push the update with your leaderboard, as players play, they will also have their data saved into that datastore, which will then be used in constructing the top 50 players onto the leaderboard.
Hopefully that all made sense, but the bottom line is you are starting with a fresh ordered data store, since you cant stick the name of your global data store into getordereddatastore and try to use those values. So in turn, only you are showing up because you are the only one in studio, while everyone is playing a version of the game without the ordered data store.
If none of that applies, then I’m not sure why only 1 person is showing up lol
You are absolutely right. I didn’t know that an ordered datastore was something else than a global one. A new datastore was created and of course im the only one inside. Thank you very much for your help! Now i just have to find a way to get the old data into the new memory.