Datastore request was added to queue. How do we fix it?

The datastore script is:

local currencyName = “Money”

local DataStore = game:GetService(“DataStoreService”):GetDataStore(“CurrencyDataStore”)

game.Players.PlayerAdded:Connect(function(player)

local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player

local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder

local ID = currencyName.."-"..player.UserId
local savedData = nil

pcall(function()
    savedData = DataStore:GetAsync(ID)
end)

if savedData ~= nil then
	currency.Value = savedData
	print("Data loaded")
else
	-- New player
	currency.Value = 100
	print("New player to the game")
end

end)

game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName…“-”…player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)

game:BindToClose(function()

-- When game is ready to shutdown

for i, player in pairs (game.Players:GetPlayers()) do
    if player then
        player:Kick("This game is shutting down") 
    end
end 	     

wait(5)

end)

This is not an error. It’s just saying it’s added it to the queue to save.

1 Like

But it does not save after leaving the game or showing the amount of money that you bought from the in game shop. :confused:

are you testing this through studio or in game? If its studio, you should add the

local ID = currencyName…"-"…player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)

into the bindtoclose function, otherwise it won’t save.

Im testing on Studio But it saves other things like if i collect coins, but if i buy in game currency against robux it wont give the amount that i order it gives only this warning messages ![Screenshot_3|690x75]

Well, the key doesn’t square with the datastore key, which is saved by the script you gave. I guess the player_364498109 key is saved in another script. Could you please show the code that saves the printed key?

this is the script for the currency shop.

local MPS = game:GetService(“MarketplaceService”)

MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 1174037154 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 500
return Enum.ProductPurchaseDecision.PurchaseGranted

elseif receiptInfo.ProductId == 1174037339 then
    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1000
    return Enum.ProductPurchaseDecision.PurchaseGranted

elseif receiptInfo.ProductId == 979188581 then 
    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	player.leaderstats.Money.Value = player.leaderstats.Money.Value + 5000
    return Enum.ProductPurchaseDecision.PurchaseGranted

elseif receiptInfo.ProductId == 979189812 then
    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	player.leaderstats.Money.Value = player.leaderstats.Money.Value + 99999
    return Enum.ProductPurchaseDecision.PurchaseGranted    

end
end

I mean, are you saving or getting the data key? If so, how often does it get the key? Quick requests may slow down the datastores to get the key. There is a cooldown of approximately 6 seconds for each request. Try checking your other scripts that use datastores.

I have a other datastore for an donation board this is the code from it:

repeat wait() until _G.DBLocked ~= nil

if _G.DBLocked == true then
script.Parent.SurfaceGui.MainFrame.ScrollingFrame.Message.Visible = true
script:Destroy()
return
end

function GetData()
local Datastore = game:GetService(“DataStoreService”):GetDataStore(“BoardData”)
local Data = Datastore:GetAsync(“Data”)
if Data == nil then
Data = {ListSize = 15, Datastore = 1, Refresh = 1, Version = 2}
end

local TD = game:GetService("DataStoreService"):GetOrderedDataStore("TopDonators")

if Data.Datastore ~= 1 then
	TD = game:GetService("DataStoreService"):GetOrderedDataStore("TopDonators"..Data.Datastore)
end

return TD:GetSortedAsync(false, Data.ListSize),Data.ListSize,Data.Refresh

end

function updateBoard(board, data, num)
script.Parent.SurfaceGui.MainFrame.Title.Title.Title.Text = “Top “…num…” Donors”

for _,v in pairs (script.Parent.SurfaceGui.MainFrame.ScrollingFrame:GetChildren()) do
	v:TweenPosition(UDim2.new(-1,0,0,v.Position.Y.Offset),'InOut','Quart',.5,true)
	wait()
	delay(1,function()
		v:Destroy()
	end)
end
local n = 0
for k, v in pairs(data) do
	local name = v.key
	local score = v.value
	local L = script.Frame:Clone()
	L.Parent = script.Parent.SurfaceGui.MainFrame.ScrollingFrame
	local ln = n + 1
	spawn(function()
		pcall(function()
			L.Number.Text = ln.."."
			L.Title.Text = game.Players:GetNameFromUserIdAsync(name)
		end)
	end)
	L.Explaination.Text = score
	L.Position = UDim2.new(1,0,0,(n* 25) + (n*5))
	L:TweenPosition(UDim2.new(0,0,0,(n* 25) + (n*5)),'InOut','Quart',.5,true)		
	n = n + 1
	if n == 1 then
		L.Title.TextColor3 = Color3.new(176/255,176/255,0/255)
		L.Explaination.TextColor3 = Color3.new(23/255, 255/255, 96/255)
		L.Number.TextColor3 = Color3.new(176/255,176/255,0/255)
		game.Workspace.Boards.R15Loader1.Configuration.userId.Value = name
		game.Workspace.Boards.R15Loader1.Tags.Container.pName.Text = game.Players:GetNameFromUserIdAsync(name)
	elseif n == 2 then
		L.Title.TextColor3 = Color3.new(185/255,185/255,185/255)
		L.Explaination.TextColor3 = Color3.new(23/255, 255/255, 96/255)
		L.Number.TextColor3 = Color3.new(185/255,185/255,185/255)
		game.Workspace.Boards.R15Loader2.Configuration.userId.Value = name
		game.Workspace.Boards.R15Loader2.Tags.Container.pName.Text = game.Players:GetNameFromUserIdAsync(name)
	elseif n == 3 then		
		L.Title.TextColor3 = Color3.new(143/255,71/255,0/255)
		L.Explaination.TextColor3 = Color3.new(23/255, 255/255, 96/255)	
		L.Number.TextColor3 = Color3.new(143/255,71/255,0/255)
		game.Workspace.Boards.R15Loader3.Configuration.userId.Value = name
		game.Workspace.Boards.R15Loader3.Tags.Container.pName.Text = game.Players:GetNameFromUserIdAsync(name)
	end
	script.Parent.SurfaceGui.MainFrame.ScrollingFrame.CanvasSize = UDim2.new(0,0,0,(n * 25) + (n*5))
	wait()
end	

end

while true do
local refreshTime = 1
pcall(function()
local pages,num,refresh = GetData()
local data = pages:GetCurrentPage()
updateBoard(script.Parent, data, num)
if refresh and typeof(refresh) == ‘number’ then
refreshTime = refresh
end
end)
wait(refreshTime * 60)
end