I set up a DataStore with data used for my global leaderboard and have come across an issue where there are too many entries in the DataStore to filter through them all as Roblox limits the rate at which you can use GetAsync()
.
Here’s what it looks like on the server (within a module script):
local DataStoreService = game:GetService("DataStoreService")
local rankedLeaderStore = DataStoreService:GetDataStore("RankedLeaders")
local leaderData = {}
local rankedLeaderDictionary = {}
RankedEvent.OnServerEvent:Connect(function(player, eventtye, equippedCards, rankedDivision, rankedElo)
if eventtye == "addLeaderStats" then
local key = player.UserId .. "1"
local dataToStore = {
KeyName = player.UserId,
name = player.Name,
cards = equippedCards,
division = rankedDivision,
elo = rankedElo
}
local success, errorMessage = pcall(function()
table.insert(leaderData, dataToStore)
end)
if not success then
print(errorMessage)
end
end
end)
Players.PlayerRemoving:Connect(function(player: Player)
for i, data in pairs(leaderData) do
if data.KeyName == player.UserId then
local key = player.UserId .. "1"
rankedLeaderStore:SetAsync(key, data)
end
end
end)
function RankedServer.SetupLeaders()
while true do
local listSuccess, pages = pcall(function()
return rankedLeaderStore:ListKeysAsync()
end)
if listSuccess then
while true do
local enemyInfo = pages:GetCurrentPage()
for _, v in ipairs(enemyInfo) do
local value = rankedLeaderStore:GetAsync(v.KeyName)
rankedLeaderDictionary[v.KeyName] = value
end
if pages.IsFinished then
break
end
pages:AdvanceToNextPageAsync()
end
end
task.wait(600)
end
end
In the SetupLeaders
function, the enemyInfo
table is saved/loaded the same way as the leaderData
table, using a different DataStore, so I didn’t include it in the code provided.
Here are the errors that I get:
Is there a way to make this work with my current system or do I need to change how I save/load the data entirely?