Ive been getting this error code lately with my datastore scripts, is there something I have put in the wrong place? Error: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests Here is the code, thanks in advance

local DataStoreService = game:GetService("DataStoreService")
local SaveDataStore = DataStoreService:GetDataStore("DataValues")


game.Players.PlayerRemoving:Connect(function(player)
	local p = player:FindFirstChild("DataValues")
	if p then
		local savedata = {}
		for i, v in pairs(p:GetChildren()) do
			savedata[v.Name] = v.Value
		end
		SaveDataStore:SetAsync(player.UserId, savedata)
	end
end)
game:BindToClose(function()
    for _, player in pairs(game.Players:GetPlayers()) do
        local p = player:FindFirstChild("DataValues")
        if p then
            local savedata = {}
                for i, v in pairs(p:GetChildren()) do
                        savedata[v.Name] = v.Value
                end
            SaveDataStore:SetAsync(player.UserId, savedata)
		        end
		end
end)

game.Players.PlayerAdded:Connect(function(player)
	local DataValues = Instance.new("Folder")
	DataValues.Name = "DataValues"
	DataValues.Parent = player

	
	local KoalaCounter = Instance.new("IntValue")
	KoalaCounter.Name = "KoalaCounter"
	KoalaCounter.Parent = DataValues
	
	local count = Instance.new("IntValue")
	count.Name = "Count"
	count.Parent = DataValues
	
	local DesertScoutV = Instance.new("IntValue")
	DesertScoutV.Name = "DesertScoutV"
	DesertScoutV.Parent = DataValues
	
	local DesertScoutQ = Instance.new("IntValue")
	DesertScoutQ.Name = "DesertScoutQ"
	DesertScoutQ.Parent = DataValues
	
	local DominusFrigQ = Instance.new("IntValue")
	DominusFrigQ.Name = "DominusFrigQ"
	DominusFrigQ.Parent = DataValues

	local DominusFrigV = Instance.new("IntValue")
	DominusFrigV.Name = "DominusFrigV"
	DominusFrigV.Parent = DataValues

	
	local data = SaveDataStore:GetAsync(player.UserId)
	if data then
		print("Data loaded")
		for i,v in pairs(DataValues:GetChildren()) do
			v.Value = data[v.Name]
		end
	end
    while wait(240) do
            local p = player:FindFirstChild("DataValues")
            if p then
                local savedata = {}
                for i, v in pairs(p:GetChildren()) do
                        savedata[v.Name] = v.Value
                end

                SaveDataStore:UpdateAsync(player.UserId, function(savedata) 
                return savedata
                end)
            end
    end 
end)

4 comments

0

Assuming there's only 1 person in the server, it might be because BindToClose and PlayerRemoving are both trying to save the player's data

0

Why is this?

0

Probably what @the8bitdude11 said as there is 2 requests at once trying to save a players data.

0

So how would I make it so the BindToClose doesnt fire on playerRemove?