So I have a GlobalLeaderboard script that is supposed to order the player names according to the number of wins they have.
The script below is located in ServerScriptService.
My issue is that my output says that I have too many datastore requests and if more keep coming, the older ones get deleted.
How do I efficiently stop this?
local dataStoreService = game:GetService("DataStoreService")
local players = game:GetService("Players")
local globalDataStore = dataStoreService:GetOrderedDataStore("Wins")
local board = workspace.Lobby.GlobalBoard
local template = board.SurfaceGui.LeaderBoard.Template:Clone()
board.SurfaceGui.LeaderBoard.Template:Destroy()
local function update()
for _,child in pairs(board.SurfaceGui.LeaderBoard:GetChildren()) do
if child:IsA("Frame") then
child:Destroy()
end
end
local success,err = pcall(function()
local data = globalDataStore:GetSortedAsync(false,40)
local page = data:GetCurrentPage()
for rank,plrData in ipairs(page) do
local userid = plrData.key
local wins = plrData.value
if rank < 3 then
local npc = workspace:FindFirstChild(rank)
if npc then
npc.UserId.Value = userid
end
end
local new = template:Clone()
new.PlrName.Text = players:GetNameFromUserIdAsync(userid)
new.PlrAmount.Text = wins
new.LayoutOrder = rank
new.Parent = board.SurfaceGui.LeaderBoard
end
end)
end
while true do
update()
wait(math.random(2,5))
spawn(function()
for _,plr in pairs(game.Players:GetPlayers()) do
globalDataStore:SetAsync(plr.UserId,plr.leaderstats.Wins.Value)
wait()
end
end)
end

3 comments
There are too many spaces in your script which makes it hard to read -_- try formatting it.
ok sorry, will edit it right now!
there, i made it better