Datastore added to queue

Im using tables for my datastore but for some reason my data gets added to queue, i don’t really know what im doing wrong.

local dataStoreService = game:GetService("DataStoreService")
local key = "Test1"
local ds = dataStoreService:GetDataStore(key)


local stats = {
	["leaderstats"] = {
		["Stages"] = 0;
	}
}

game:GetService("Players").PlayerAdded:Connect(function(plr)
	local data = ds:GetAsync(key.."/"..plr.UserId)
	print(data)
	
	for i, StatTable in pairs(stats) do
		local folder = Instance.new("Folder")
		folder.Name = i
		folder.Parent = plr
		
		for stat, value in pairs(StatTable) do
			local val_new = Instance.new("NumberValue")
			val_new.Name = stat
			val_new.Value = value
			val_new.Parent = folder
			if data then
				val_new.Value = data[folder.Name][stat]
			end
		end
	end
end)


local function SaveData(plr)
	local tableToSave = stats

	for i, folder in pairs(plr:GetChildren()) do
		if folder.ClassName == "Folder" then
			for i, stat in pairs(folder:GetChildren()) do
				tableToSave[folder.Name][stat.Name] = stat.Value
			end
		end
	end

	if tableToSave then
		local tries = 0
		repeat
			tries += 1
			local succ, err = pcall(function()
				local data = ds:UpdateAsync(key..'/'..plr.UserId,function(olddata)
					return tableToSave	
				end)
			end)
			if err then warn(err) task.wait(6) end
		until succ or tries == 3
		print("Data saved for " .. plr.Name)
	end
end

game:GetService("Players").PlayerRemoving:Connect(function(plr)
	SaveData(plr)
end)

game:BindToClose(function()
	for _, plr in ipairs(game:GetService("Players"):GetPlayers()) do
		coroutine.wrap(SaveData)(plr)
	end
end)

That message just means you are sending a large amount of requests within a minute.

Generally, it should be fine. However, it is possible that some other scripts in your game are sending large amounts of requests, which could potentionally block some of your intended requests. Search around for any other scripts using datastores

no there are none, It was mostlikely that studio crashed for a bit, can that be the issue?

It should not be the issue. When that message appears, it means that there are too many requests. Maybe try to add a small delay between them.

There is already a delay. task.wait(6). Or am i doing something else wrong here?

Just try wait(.5) or something

Nah the datastore api says you need to wait exactly 6 seconds before making another call to prevent data issues

I encounter those all the time. It’s not an error or anything, just a simple warning and just like what @SeargentAUS and @Claym1x said, it should be okay as long nothing messes up.

Its just, idk what im doing wrong. I even save the values in a table and it still occurs. Maybe ill change the updateAsync.

1 Like