DataStore request was added to a queue error

I’m trying to make a simple datastore script but some problems occurred.
I keep getting this error

'DataStore request was added to a queue. If the request queue fills, further requests will be dropped. Try sending fewer requests. ’

which is extremely annoying. I tried wrapping the datastore script in a pcall, I tried adding waits in between the Datastore1:SetAsync bit, but no, nothing works.

Here’s what the script looks like in the explorer:
image
The script in the blue box :+1:

local Datastore = game:GetService("DataStoreService")
local Datakey = 640725830
local Datastore1 = Datastore:GetDataStore(Datakey)



game.Players.PlayerAdded:Connect(function(plr)
	for _, folder in pairs(script.Datastores:GetDescendants()) do
		if folder:IsA('Folder') then
			local v = folder:Clone()
			v.Parent = plr
			for _, value in ipairs(v:GetDescendants()) do
				if value.ClassName:match('Value') then
					wait()
					value.Value = Datastore1:GetAsync(plr.UserId,value) or 0

					Datastore1:SetAsync(plr.UserId, value.Value)
					
				end
			end
			
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	for _, folder in pairs(plr:GetDescendants()) do
		if folder:IsA('Folder') then
			for _, value in ipairs(folder:GetDescendants()) do
				if value.ClassName:match('Value') then
					wait(0.1)
					value.Value = Datastore1:SetAsync(plr.UserId,value.Value) or 0
					wait(0.1)
				end
			end
			
		end
	end
end)
1 Like

Well you are indeed requesting a lot of saves, what I recommend you do instead is, loop through everything, put everything inside of a table, then simply save that table

1 Like

This isn’t an error but a warning that you’re sending too many datastore requests for the same key.
You need to find a way to use a different datastore key or reduce how many you’re sending by saving a table.
FYI: Instead of

if value.ClassName:match('Value') then

You can do

if value:IsA("ValueBase") then

Since the ValueBase group contains every type of Value.

1 Like

Alright, here’s my new script (still gives the warning so please help)

local PlayerData = {}
local Datastore = game:GetService("DataStoreService")
local DataPoints = 0
local Datakey1 = 640725830
local Datastore1 = Datastore:GetDataStore(Datakey1)



game.Players.PlayerAdded:Connect(function(plr)
	for _, folder in pairs(script.Datastores:GetDescendants()) do
		if folder:IsA('Folder') then
			local v = folder:Clone()
			v.Parent = plr
			for _, value in ipairs(v:GetDescendants()) do
				
				if value.ClassName:match('Value') then
					
					value.Value = Datastore1:GetAsync(plr.UserId,value) or 0
					
					DataPoints = DataPoints + 1
					
					table.insert(PlayerData,DataPoints,(Datastore1:GetAsync(plr.UserId,value.Value) or 0))

					Datastore1:SetAsync(plr.UserId, PlayerData)
					
				end
			end
			
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
Datastore1:SetAsync(plr.UserId,PlayerData)			
end)

You could try it like this

      for _, value in ipairs(v:GetDescendants()) do
			
			if value.ClassName:match('Value') then
				
				value.Value = Datastore1:GetAsync(plr.UserId,value) or 0
				
				DataPoints = DataPoints + 1
				
				table.insert(PlayerData,DataPoints,(Datastore1:GetAsync(plr.UserId,value.Value) or 0))

				
			end
		end
Datastore1:SetAsync(plr.UserId, PlayerData)
1 Like

Serialized value exceeds 260,000 character limit.

try aGaIn.
(Why did it not work, now I’m even MORE confused on my datastore script. I have to get this done by oct 31 to release, so please respond.)

Maybe you should try to use more data stores than just one or you could try adding wait(.3)

1 Like

No, still didnt work sadly. :frowning:

Instead of saving all values seperately you can better add them to a table and save the table only then you shouldnt have the problem

local PlayerData = {}
local Datastore = game:GetService("DataStoreService")
local Datakey1 = 640725830
local Datastore1 = Datastore:GetDataStore(Datakey1)

game.Players.PlayerAdded:Connect(function(plr)
	for _, folder in pairs(script.Datastores:GetDescendants()) do
		if folder:IsA('Folder') then
			local v = folder:Clone()
			v.Parent = plr
			PlayerData[plr] = {}
			for _, value in ipairs(v:GetDescendants()) do
				
				if value.ClassName:match('Value') then
					
					value.Value = Datastore1:GetAsync(plr.UserId,value.Name) or 0
					
					PlayerData[plr][value.Name] = value.Value
					
					value.Changed:Connect(function()
						PlayerData[plr][value.Name] = value.Value
					end)
					
				end
			end
			Datastore1:SetAsync(plr.UserId, PlayerData[plr])
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	Datastore1:SetAsync(plr.UserId,PlayerData[plr])
	PlayerData[plr] = nil		
end)
1 Like

I have not tested it so if you have any issues with or need more explanation let me know :slight_smile:

1 Like

The DataStore doesn’t even save :frowning:

Will check now now that I am on pc :slight_smile:

1 Like

This works fine for me it changes the value when you change it Example: Player.Boosters.Boost1 = 100 then you rejoin then it will set the boost1 to 100 here is the code and the issue about the datastore queue has been fixed too! :slight_smile: enjoy!

local PlayerData = {}
local Datastore = game:GetService("DataStoreService")
local Datakey1 = 640725830
local Datastore1 = Datastore:GetDataStore(Datakey1)

game.Players.PlayerAdded:Connect(function(plr)
	for _, folder in pairs(script.Datastores:GetDescendants()) do
		if folder:IsA('Folder') then
			local Header = folder:Clone()
			Header.Parent = plr
			PlayerData[plr] = {}
			local Data = Datastore1:GetAsync(plr.UserId)
			for _, value in pairs(Header:GetDescendants()) do
				
				if value.ClassName:match('Value') then
					value.Value = Data and Data[value.Name] or 0
					PlayerData[plr][value.Name] = value.Value
					
					value.Changed:Connect(function()
						PlayerData[plr][value.Name] = value.Value
					end)
					
				end
			end
			--Datastore1:SetAsync(plr.UserId,PlayerData[plr])
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	Datastore1:SetAsync(plr.UserId,PlayerData[plr])
	PlayerData[plr] = nil		
end)
2 Likes

Thank you! But I have to point out that Changed is not good and GetPropertyChangedSignal is really cool and good.

It always worked for me tho it works fine for values and never had any problem with it and nobody ever complained about data loss so xd but you can be right not sure tho I used changed already for like 5 years

1 Like

Ok i will try it :smiley: . I’d prefer GetPropertyChangedSignal() though.

Yeah guess it depends what people like to use tho if changed was really bad than roblox had removed it but you’re welcome feel free to change whatever you want if you need more help just let me know :slight_smile:

1 Like

OOOOOOOHHH, GetPropertyChangedSignal() only fires when a property is changed! It was underneath our noses the whole time :crazy_face: . Thank you for helping me with my datastore script! I can’t believe how naive I just was! (does naive work in this context?)

It is fine I am glad I could help I wish you good luck with your project :smiley: I only used GetPropertyChangedSignal for like example knowing if the visible property is changed of an UI. So good luck on your development journery :smiley:

1 Like

Use Changed for ValueObjects, not GetPropertyChangedSignal. Changed for ValueObjects is specially designed to fire when only the value changes and it is called with the new value as a parameter. GetPropertyChangedSignal is for other instances when needing granular change check control. It is also slightly slower because it is a callback, not a direct member of the instance.

cc @DevLevii @IUClDS

2 Likes