DataStore Not Working

Hello, I am working on a saving system and I’m getting the error message "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = DiscoveredSpells-1670731971 "

I’m new to DataStores so can someone tell me what I’m doing wrong?

local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SpellsFolder = ReplicatedStorage:WaitForChild("Spells")

local SpellsDataStore = DataStoreService:GetDataStore("SpellData")

game.Players.PlayerAdded:Connect(function(Player)
	
	local Inventory = Instance.new("Folder",Player)
	Inventory.Name = "Inventory"
	
	local DiscoverdSpellsFolder = Instance.new("Folder",Player)
	DiscoverdSpellsFolder.Name = "DiscoveredSpells"
	
	local SpellsFolder = Instance.new("Folder",Inventory)
	SpellsFolder.Name = "Spells"
	
	local ItemsFolder = Instance.new("Folder",Inventory)
	ItemsFolder.Name = "Items"
	
	local PlayerData
	
	local Success,ErrorMessage = pcall(function()
		PlayerData = SpellsDataStore:GetAsync("DiscoveredSpells-"..Player.UserId)
	end)
	
	if Success and PlayerData then 
		print("DataStore Success")
		for _, SpellName in pairs(PlayerData) do
			if DiscoverdSpellsFolder:FindFirstChild(SpellName) then
				local SpellValue = Instance.new("StringValue")
				SpellValue.Name  = SpellName
				SpellValue.Parent = DiscoverdSpellsFolder
			end
		end
	else
		print("DataStore Error")
		warn("ErrorMessage")
	end
	
end)


game.Players.PlayerRemoving:Connect(function(Player)
	
	local SpellsTable = {}
	
	for _, Spell in pairs(Player:WaitForChild("DiscoveredSpells"):GetChildren()) do
		table.insert(SpellsTable,Spell.Name)
	end
	
	local Success,ErrorMessage = pcall(function()
		SpellsDataStore:SetAsync("DiscoveredSpells-"..Player.UserId,SpellsTable)
	end)                               
	
	if Success then
		print("DataStore Success")
	else
		print("DataStore Error")
		warn("ErrorMessage")
	end
	
	
end)

game:BindToClose(function()
	for _, Player in pairs(game.Players:GetPlayers()) do
		local SpellsTable = {}
		for _, Spell in pairs(Player:WaitForChild("DiscoveredSpells"):GetChildren()) do
			table.insert(SpellsTable,Spell.Name)
		end

		local Success,ErrorMessage = pcall(function()
			SpellsDataStore:SetAsync("DiscoveredSpells-"..Player.UserId,SpellsTable)
		end)                               

		if Success then
			print("DataStore Success")
		else
			print("DataStore Error")
			warn("ErrorMessage")
		end
	end

end)
2 Likes

That doesn’t mean it’s not working, the problem is that you are sending too many requests.

2 Likes

From what I know the server can only handle 500 requests per second for the server, so I would try to save all the values within a single datastore so you have fewer requests, try using an array to sort the data.

2 Likes

I can give you a code example, that I’ve been using for my game.

2 Likes

Ok, that would be great thanks

1 Like

Alright, so this I’m using for like a store for an obby game so it deals with 2 values one is jump the other is speed.

local SName = "Speed"
local JName = "Jump"

local DataStore = game:GetService("DataStoreService"):GetDataStore("UpgradeData")
game.Players.PlayerAdded:Connect(function(player)


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


	-- Speed -- 
	local Speed = Instance.new("NumberValue",folder)
	Speed.Name = SName




	-- Jump --
	local Jump = Instance.new("NumberValue",folder)
    Jump.Name = JName
	
	local savedData = nil

	local ValueS = Speed 
	local ValueJ = Jump



	pcall(function()

		savedData = DataStore:GetAsync(player.UserId)
	end)


	if savedData ~= nil then
		ValueS.Value = savedData[1]
		ValueJ.Value = savedData[2]
		
		print("Data Loaded")
	else
		ValueS.Value = 0
		ValueJ.Value = 0
		print("New Player")
	end




end)

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

	local SaveData =  {}
	for _,Child in pairs(player.Materials:GetChildren())do
		table.insert(SaveData,Child.Value)
	end
	DataStore:SetAsync(player.UserId, SaveData)
end)

game:BindToClose(function()



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

	wait(5)	

end)



Edit: Just change the value names and folder names. I’d suggest changing the variable name also.

2 Likes

Is that all did I answer your question?

2 Likes

Yeah, I understand now. Thanks for the help

2 Likes

Np glad I could help you out, it makes my day also when I’m able to help someone out! :smiley:

2 Likes