Roblox Data Store Added To queue

I keep getting this error from my saving leaderstats " DataStore request was added to queue. If request queue fills, further requests will be dropped" script and players data wont save any ideas? This is my script.

"lua local DataStore = game:GetService(“DataStoreService”)
local ds = DataStore:GetDataStore(“LeaderStatSave”)
local killsDataStore = DataStore:GetDataStore(“KillsDataStore”)
local gloveDataStore = DataStore:GetDataStore(“GloveDataStore”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

– Set up the RemoteEvent for purchases
local purchaseEvent = ReplicatedStorage:FindFirstChild(“PurchaseEvent”)
if not purchaseEvent then
purchaseEvent = Instance.new(“RemoteEvent”)
purchaseEvent.Name = “PurchaseEvent”
purchaseEvent.Parent = ReplicatedStorage
end

– Connects when a new player joins the game
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”, player)
leaderstats.Name = “leaderstats”

local Pushes = Instance.new("NumberValue", leaderstats)
Pushes.Name = "Pushes"
Pushes.Value = ds:GetAsync(player.UserId .. "-Pushes") or 0


local Glove = Instance.new("StringValue", leaderstats)
Glove.Name = "Arm"
Glove.Value = gloveDataStore:GetAsync(player.UserId .. "-Glove") or script.StarterGlove.Value

local function saveStats()
	ds:SetAsync(player.UserId .. "-Pushes", Pushes.Value)
	gloveDataStore:SetAsync(player.UserId .. "-Glove", Glove.Value)
end

Pushes.Changed:Connect(saveStats)
Glove.Changed:Connect(saveStats)

end)

– Save data when player is leaving the game
game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player:FindFirstChild(“leaderstats”)
if leaderstats then
ds:SetAsync(player.UserId … “-Pushes”, leaderstats.Pushes.Value)
gloveDataStore:SetAsync(player.UserId … “-Glove”, leaderstats.Arm.Value)
end
end)

– Handle purchase requests
purchaseEvent.OnServerEvent:Connect(function(player, itemName, price)
local leaderstats = player:FindFirstChild(“leaderstats”)
if not leaderstats then return end

local coins = leaderstats:FindFirstChild("Pushes")
local arm = leaderstats:FindFirstChild("Arm")
if coins and arm and coins.Value >= price then
	coins.Value = coins.Value - price
	arm.Value = itemName
	gloveDataStore:SetAsync(player.UserId .. "-Glove", arm.Value)
	ds:SetAsync(player.UserId .. "-Pushes", coins.Value)
else
	warn("Purchase failed for " .. player.Name .. ": not enough Pushes or missing leaderstats.")
end

end)"

Updating the datastore every time the value changes is a surefire way to fill up the max 60 requests per minute per server on DataStoring. You can just autosave every minute or longer because you already save data when the player leaves

1 Like