I keep getting an error showing “DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Data Store”
What is the issue?
Every time I load into my game it keeps showing that error
What solutions have you tried so far?
Looking for a solution
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStoreV3")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Coins = Instance.new("NumberValue", leaderstats)
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
local donates = Instance.new("IntValue")
donates.Name = "R$ Donated"
donates.Parent = player
donates.Value = 0
local DJumps = Instance.new("NumberValue",player)
DJumps.Name = "DJumps"
local MaxJumps = Instance.new("NumberValue",DJumps)
MaxJumps.Name = "MaxDJumps"
MaxJumps.Value = 1
local Boost = Instance.new("NumberValue",DJumps)
Boost.Name = "Boost"
Boost.Value = MaxJumps.Value
local Need = Instance.new("NumberValue",DJumps)
Need.Name = 'Need'
Need.Value = 100
local Strength = Instance.new("NumberValue", leaderstats)
Strength.Name = "Strength"
Strength.Parent = leaderstats
Strength.Value = 0
local Capacity = Instance.new("NumberValue", player)
Capacity.Name = "Capacity"
Capacity.Parent = player
Capacity.Value = 10
local Diamonds = Instance.new("NumberValue", leaderstats)
Diamonds.Name = "Diamonds"
Diamonds.Parent = leaderstats
Diamonds.Value = 0
local Rank = Instance.new("IntValue", leaderstats)
Rank.Name = "Rank"
Rank.Parent = leaderstats
Rank.Value = "MiniFlyWeight"
local Level = Instance.new("NumberValue")
Level.Name = "Level"
Level.Parent = player
Level.Value = 1
local Exp = Instance.new("NumberValue")
Exp.Name = "Exp"
Exp.Parent = Level
Exp.Value = 0
local MaxExp = Instance.new("NumberValue")
MaxExp.Name = "MaxExp"
MaxExp.Parent = Level
MaxExp.Value = 100
Strength.Changed:Connect(function()
if Strength.Value >= Capacity.Value then
Strength.Value = Capacity.Value
end
end)
Exp.Changed:Connect(function(Val)
if Exp.Value >= MaxExp.Value then
Level.Value = Level.Value + 1
Exp.Value = 0
MaxExp.Value = MaxExp.Value + 10
end
end)
local key = player.UserId
local data
local success,msg = pcall(function()
data = DataStore:GetAsync(key)
end)
if data then
print("Data Loaded")
Strength.Value = data.S
Capacity.Value = data.C
Rank.Value = data.R
Diamonds.Value = data.D
Coins.Value = data.Cs
MaxJumps.Value = data.M
Need.Value = data.N
Level.Value = data.L
Exp.Value = data.E
MaxExp.Value = data.m
donates.Value = data.d
else
print("Error")
warn(msg)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = player.UserId
local data = {
C = player.Capacity.Value,
Cs = player.leaderstats.Coins.Value,
S = player.leaderstats.Strength.Value,
D = player.leaderstats.Diamonds.Value,
R = player.leaderstats.Rank.Value,
M = player.DJumps.MaxDJumps.Value,
N = player.DJumps.Need.Value,
L = player.Level.Value,
E = player.Level.Exp.Value,
m = player.Level.MaxExp.Value,
d = player.leaderstats.donates.Value,
}
local success,msg = pcall(function()
DataStore:SetAsync(key,data)
end)
if success then
print("Data Saved!")
end
end)
game.ReplicatedStorage:WaitForChild("Boost").OnServerEvent:Connect(function(player)
if player.leaderstats.Coins.Value >= player.DJumps.Need.Value then
player.leaderstats.Coins.Value -= player.DJumps.Need.Value
player.DJumps.Need.Value *= 10
player.DJumps.MaxDJumps.Value += 1
print(player.DJumps.MaxDJumps.Value)
else
print("Not Enough Coins!")
end
end)
local key = player.UserId
local data
local success,msg = pcall(function()
data = DataStore:GetAsync(key)
end)
if data then
print("Data Loaded")
else
print("Error")
warn(msg)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local key = player.UserId
local data = {
["Capacity"] = player.Capacity,
}
local success,msg = pcall(function()
DataStore:SetAsync(key,data)
end)
if success then
print("Data Saved!")
end
end)
This shouldn’t fix the error message, the problem is that you do too many SetAsync or GetAsync requests. Is this the only script you do data saving in?
Okay so in both the datastore and leaderboard script you save something with the same UserId when a player leaves.
Due to roblox their datastore limits, there HAS to be a 6 second interval between saving with the same key
Since the leaderboard datastore is different from the normal datastore you can just change their keys. In the normal datastore you save with theplayer.UserId. And in the leaderboard datastore you save with for example"leaderboard_"..player.UserId. Since they both have different keys, it will not hit the datastore limits
Do not forget to also use the same key used when doing :GetAsync()
local datastoreservice = game:GetService("DataStoreService")
local datastore = datastoreservice:GetOrderedDataStore("leaderboarddatastore")
local player = game:GetService("Players")
local coinsleaderboard = workspace:WaitForChild("Coinsleaderboard")
local frame = coinsleaderboard:WaitForChild("SurfaceGui"):WaitForChild("Frame"):WaitForChild("ScrollingFrame")
local UIGridLayout = frame:WaitForChild("UIGridLayout")
local tempclone = script:WaitForChild("Temp")
local playerisingame = {}
local function newplayer(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Coins = Instance.new("NumberValue", leaderstats)
Coins.Name = "Coins"
local coinsdata
pcall(function()
coinsdata = datastore:GetAsync(player.UserId.."_leaderboard")
end)
if coinsdata ~= nil then
Coins.Value = coinsdata
end
end
local function Updateguileaderboard()
local pages
pcall(function()
pages = datastore:GetSortedAsync(false,10)
end)
if pages ~= nil then
local currentpage = pages:GetCurrentPage()
for i, v in pairs(frame:GetChildren()) do
if v:IsA("Frame") then
v:Destroy()
end
end
for i, data in ipairs(currentpage) do
local username
pcall(function()
username = player:GetNameFromUserIdAsync(data["key"])
end)
if username ~= nil then
local tempframe = tempclone:Clone()
tempframe.Parent = frame
tempframe:WaitForChild("Rank").Text = "#"..i
tempframe:WaitForChild("Player").Text = username
tempframe:WaitForChild("Coins").Text = data["value"]
end
end
local size = Vector2.new(1, 0.1) * frame.AbsoluteSize
UIGridLayout.CellSize = UDim2.new(0, size.X, 0, size.Y)
frame.CanvasSize = UDim2.new(0, 0, 0, UIGridLayout.AbsoluteContentSize.Y)
end
end
local function playerremoving(player)
playerisingame[player] = nil
pcall(function()
local tempcoins = player:WaitForChild("leaderstats"):WaitForChild("Coins").Value
if tempcoins >= 1 then
datastore:SetAsync(player.UserId.."_leaderboard", tempcoins)
Updateguileaderboard()
end
end)
end
player.PlayerAdded:Connect(function(player)
if playerisingame[player] == nil then
newplayer(player)
end
end)
playerisingame = player:GetPlayers()
for i, v in pairs(playerisingame) do
newplayer()
end
player.PlayerRemoving:Connect(playerremoving)
Updateguileaderboard()