Hello! I recently made a script for a global leaderboard in my game. The only problem is that my data gets lost everytime.
This is the error: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests
local sg = script.Parent local sample = script:WaitForChild("Sample") local sf = sg:WaitForChild("ScrollingFrame") local ui = sf:WaitForChild("UI") local dataStoreService = game:GetService("DataStoreService") local dataStore = dataStoreService:GetOrderedDataStore("Leaderboard") wait(10) script.Parent.Update.Text = "Updating leaderboard.." script.Parent.Loading.Visible = false while true do for i,plr in pairs(game.Players:GetChildren()) do if plr.UserId>0 then local w = plr.leaderstats.Coins.Value if w then pcall(function() dataStore:UpdateAsync(plr.UserId,function(oldVal) return tonumber(w) end) end) end end end local smallestFirst = false local numberToShow = 100 local minValue = 1 local maxValue = 10e30 local pages = dataStore:GetSortedAsync(smallestFirst, numberToShow, minValue, maxValue) local top = pages:GetCurrentPage() local data = {} for a,b in ipairs(top) do local userid = b.key local points = b.value local username = "[Failed To Load]" local s,e = pcall(function() username = game.Players:GetNameFromUserIdAsync(userid) end) if not s then warn("Error getting name for "..userid..". Error: "..e) end local image = game.Players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size150x150) table.insert(data,{username,points,image}) end ui.Parent = script sf:ClearAllChildren() ui.Parent = sf for number,d in pairs(data) do local name = d[1] local val = d[2] local image = d[3] local color = Color3.new(1,1,1) if number == 1 then color = Color3.new(1,1,0) elseif number == 2 then color = Color3.new(0.9,0.9,0.9) elseif number == 3 then color = Color3.fromRGB(166, 112, 0) end local new = sample:Clone() new.Name = name new.LayoutOrder = number new.Image.Image = image new.Image.Place.Text = number new.Image.Place.TextColor3 = color new.PName.Text = name new.Value.Text = val new.Value.TextColor3 = color new.PName.TextColor3 = color new.Parent = sf end wait() sf.CanvasSize = UDim2.new(0,0,0,ui.AbsoluteContentSize.Y) script.Parent.Update.Text = "Updating leaderboard in 3 minutes..." wait(200) end
I save data every 200 seconds, so I don't know why it gets lost.
Try using 'SetAsync'
21 dataStore:UpdateAsync(plr.UserId,function(oldVal) 22 return tonumber(w) 23 end)