Datastore request was added to queue

Whenever I shut down my server using this code, I’m constantly getting the error “Datastore request was added to queue.” What is causing that?

I don’t think I was writing to the same key constantly, but I could be wrong.

--// Variables
local DataStoreService = game:GetService("DataStoreService")
local bombData = DataStoreService:GetDataStore("bombData")
local trailData = DataStoreService:GetDataStore("trailData")
local RunService = game:GetService("RunService")


local function setupPlayerData(player)
	
	local PlayerBombInventory = Instance.new("Folder")
		PlayerBombInventory.Name = "BombInventory"
		PlayerBombInventory.Parent = player
	
	local PlayerTrailInventory = Instance.new("Folder")
		PlayerTrailInventory.Name = "TrailInventory"
		PlayerTrailInventory.Parent = player
	
	
	local success, data = pcall(function()
		return bombData:GetAsync(player.UserId)
	end)
	
	if success then
		if data then
			for i,v in pairs(data) do
				local BombValue = Instance.new("StringValue")
				BombValue.Name = tostring(v.Name)
				BombValue.Value = tostring(v.Value)
				BombValue.Parent = PlayerBombInventory
			end
		else
			warn("No previous data found; creating new data.")
		end
	end	
	
	local trailSuccess, trailData = pcall(function()
		return trailData:GetAsync(player.UserId)
	end)
		
	if trailSuccess then
		if trailData then
			for i,v in pairs(trailData) do
				local TrailValue = Instance.new("StringValue")
				TrailValue.Name = tostring(v.Name)
				TrailValue.Value = tostring(v.Value)
				TrailValue.Parent = PlayerTrailInventory
			end
		else
			warn("No previous data found; creating new data.")
		end
	end
	
	
end

local function saveOnExit(player)
	local StoredBombs = {}
	local StoredTrails = {}
	
	
	for i, v in next, player.BombInventory:GetChildren() do
		table.insert(StoredBombs, {Name = v.Name, Value = v.Value})
	end
	
	if StoredBombs then
		local success, err = pcall(function()
			bombData:SetAsync(player.UserId, StoredBombs)
		end)
		if not success then
			warn("CANNOT SAVE DATA!")
		end	
	end
	
	for i, v in next, player.TrailInventory:GetChildren() do
		table.insert(StoredTrails, {Name = v.Name, Value = v.Value})
	end
	
	if StoredTrails then
		local trailSuccess, trailErr = pcall(function()
			trailData:SetAsync(player.UserId, StoredTrails)
		end)
		if not trailSuccess then
			warn("CANNOT SAVE DATA!")
		end	
	end
	
end

game:BindToClose(function() 
	for _, player in ipairs(game.Players:GetPlayers()) do
		coroutine.wrap(saveOnExit)(player)
	end
end)

game.Players.PlayerAdded:Connect(setupPlayerData)
game.Players.PlayerRemoving:Connect(saveOnExit)

this is normal. It will always add to the queue no matter how little you save data.

2 Likes

It concerned me because it also claimed that “further requests will be dropped”

1 Like

yes, as I said its normal with datastore saving. It says that each time you save data.

1 Like

@sniper74will It can be alarming, as requests will be revoked if there is too much.

Anyways, which data store is saying it is being queued? I see there is 2 datastore.

1 Like


https://gyazo.com/2e777df7ec788a86b5274e6be7b36b7e

It’s not really an error.


https://gyazo.com/13a3ceb50ec4e18e7c0b701a91eae274

Anyways you should combine your data into one datastore into tables, so when you leave you only have to perform one set request.

1 Like

It’s because the player is leaving too often, this can happen in studio or with a leaderboard that saves too often. Maybe try switching to datastore 2?

1 Like

Its only with that key it means you are saving to the data store multiple times with the same key.

1 Like