Data Store request was added to queue

  1. What do you want to achieve?
    Hey, I am trying to Save the Player’s Strength Level using Data Store
  2. What is the issue?
    When I play the game it prints Strength Loaded Successfully but when I leave the game it doesn’t print Strength Saved Successfully but instead gives an error in the output: “DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 926196310”
  3. What solutions have you tried so far?
    I have tried saving all three values to One Data Store but still gives the same result. I have also tried reading other posts but it didn’t quite help.
local DataStoreService = game:GetService("DataStoreService")
local StrengthLevelDataStore = {
	StrengthlevelDS = DataStoreService:GetDataStore("StrengthLevel"),
	StrengthcurrentexpDS = DataStoreService:GetDataStore("StrengthCurrentExp"),
	StrengthexpleftDS = DataStoreService:GetDataStore("StrengthExpLeft")
}

game.Players.PlayerAdded:Connect(function(Player)
	local Skills = Instance.new("Folder")
	Skills.Name = "Skills"
	Skills.Parent = Player
	
	local Strength = Instance.new("Folder")
	Strength.Name = "Strength"
	Strength.Parent = Skills
	
	local StrengthLevel = Instance.new("IntValue")
	StrengthLevel.Name = "StrengthLevel"
	StrengthLevel.Parent = Strength
	StrengthLevel.Value = 1
	
	local StrengthExpLeft = Instance.new("IntValue")
	StrengthExpLeft.Name = "StrengthExpLeft"
	StrengthExpLeft.Parent = Strength
	StrengthExpLeft.Value = 100
	
	local StrengthCurrentExp = Instance.new("IntValue")
	StrengthCurrentExp.Name = "StrengthCurrentExp"
	StrengthCurrentExp.Parent = Strength
	StrengthCurrentExp.Value = 0
	
	local playerUserId = "Player: "..Player.UserId
	local StrengthLevelDataAsync = {
		StrengthlevelDA = DataStoreService:GetDataStore("StrengthLevel"),
		StrengthcurrentexpDA = DataStoreService:GetDataStore("StrengthCurrentExp"),
		StrengthexpleftDA = DataStoreService:GetDataStore("StrengthExpLeft")
	}

	local success,errormessage = pcall(function()
		StrengthLevelDataAsync.StrengthlevelDA = StrengthLevelDataStore.StrengthlevelDS:GetAsync(playerUserId)
		StrengthLevelDataAsync.StrengthcurrentexpDA = StrengthLevelDataStore.StrengthcurrentexpDS:GetAsync(playerUserId)
		StrengthLevelDataAsync.StrengthexpleftDA = StrengthLevelDataStore.StrengthexpleftDS:GetAsync(playerUserId)
	end)
	
	if success then
		if StrengthLevelDataAsync.StrengthlevelDA == 0 then
			StrengthLevel.Value = 1
		else 
			StrengthLevel.Value = StrengthLevelDataAsync.StrengthlevelDA
		end
		if StrengthLevelDataAsync.StrengthexpleftDA == 0 then
			StrengthExpLeft.Value = 100
		else 
			StrengthExpLeft.Value = StrengthLevelDataAsync.StrengthexpleftDA
		end
		StrengthCurrentExp.Value = StrengthLevelDataAsync.StrengthcurrentexpDA
		local StrengthEventLoad = game:GetService("ReplicatedStorage"):WaitForChild("SavingRemoteEvents").Skills.strengthsave
		StrengthEventLoad:FireClient(Player)
		print("Strength Loaded Successfully!")
	else
		print("An Error occured while Loading Strength")
	end
end)
1 Like

This happens when you call a datastore request more than 1 time under 6-8 secs.

1 Like

So should I use a wait after storing each value?

Create a datastore for each player instead of creating a datastore for each value.

And here is the data store limitation.

https://developer.roblox.com/en-us/articles/Datastore-Errors#server-limits

2 Likes

I’ve experienced this issue before.
The error shows up if you’re saving data too quickly. As @dollychun showed, there are datastore limits. I suggest possibly adding a debounce or using an autosave

1 Like

Thanks for the suggestion I will surely try that!

@dollychun I followed your advice and came up with this.
This code works but when I leave the game it prints “An Error occurred while saving Strength”
And it also gives an error message " 14:56:30.811 - 104: Cannot store Dictionary in data store. Data stores can only accept valid UTF-8 characters."

local DataStoreService = game:GetService("DataStoreService")
local StoringStrength = DataStoreService:GetDataStore("StrengthLevel")


game.Players.PlayerAdded:Connect(function(Player)
	
	local Skills = Instance.new("Folder")
	Skills.Name = "Skills"
	Skills.Parent = Player
	
	local Strength = Instance.new("Folder")
	Strength.Name = "Strength"
	Strength.Parent = Skills
	
	local StrengthLevel = Instance.new("IntValue")
	StrengthLevel.Name = "StrengthLevel"
	StrengthLevel.Parent = Strength
	StrengthLevel.Value = 1
	
	local StrengthExpLeft = Instance.new("IntValue")
	StrengthExpLeft.Name = "StrengthExpLeft"
	StrengthExpLeft.Parent = Strength
	StrengthExpLeft.Value = 100
	
	local StrengthCurrentExp = Instance.new("IntValue")
	StrengthCurrentExp.Name = "StrengthCurrentExp"
	StrengthCurrentExp.Parent = Strength
	StrengthCurrentExp.Value = 0
	
	local playerUserId = "Player: "..Player.UserId
	
	
    local data

	local success,errormessage = pcall(function()
		data = StoringStrength:GetAsync(playerUserId)
	end)
	
	if success then
		if data then
		    StrengthLevel.Value = data.StrengthLevel
            StrengthExpLeft.Value = data.StrengthExpLeft
		    StrengthCurrentExp.Value = data.StrengthCurrentExp
		end
		--Firing the event
		
		local StrengthEventLoad = game:GetService("ReplicatedStorage"):WaitForChild("SavingRemoteEvents").Skills.strengthsave
		StrengthEventLoad:FireClient(Player)
		print("Strength Loaded Successfully!")
	else
		print("An Error occured while Loading Strength")
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local playerUserId = "Player: "..Player.UserId
	
	local StrengthData = {
		StrengthLevel = Player.Skills.Strength.StrengthLevel,
		StrengthExpLeft = Player.Skills.Strength.StrengthExpLeft,
		StrengthCurrentExp = Player.Skills.Strength.StrengthCurrentExp
	}
	local success,errormessage = pcall(function()
		StoringStrength:SetAsync(playerUserId,StrengthData)
	end)
	if success then 
		print("Strength Saved Successfully!")
	else
		warn(errormessage)
		print("An Error occured while saving Strength")
	end
end)

You can’t save table in datastore. instead, you can convert table to string with

so, change

	local StrengthData = {
		StrengthLevel = Player.Skills.Strength.StrengthLevel,
		StrengthExpLeft = Player.Skills.Strength.StrengthExpLeft,
		StrengthCurrentExp = Player.Skills.Strength.StrengthCurrentExp
	}
	local success,errormessage = pcall(function()
		StoringStrength:SetAsync(playerUserId,StrengthData)
	end)

to

	local StrengthData = {
		StrengthLevel = Player.Skills.Strength.StrengthLevel,
		StrengthExpLeft = Player.Skills.Strength.StrengthExpLeft,
		StrengthCurrentExp = Player.Skills.Strength.StrengthCurrentExp
	}
	local success,errormessage = pcall(function()
		StoringStrength:SetAsync(playerUserId,HTTPService:JSONEncode(StrengthData))
	end)

and

	local success,errormessage = pcall(function()
		data = StoringStrength:GetAsync(playerUserId)
	end)

to

	local success,errormessage = pcall(function()
		data = HTTPService:JSONDecode(StoringStrength:GetAsync(playerUserId))
	end)

@dollychun I tried it but now the error doesn’t appear and it doesn’t save the data

Did you define HTTPService?
If not, add this to the first line of code

local HTTPService = game:GetService("HTTPService")

I did define HTTPService anything else u see wrong in the code?

Change to

	local StrengthData = {
		StrengthLevel = Player.Skills.Strength.StrengthLevel,
		StrengthExpLeft = Player.Skills.Strength.StrengthExpLeft,
		StrengthCurrentExp = Player.Skills.Strength.StrengthCurrentExp
	}
	local success,errormessage = pcall(function()
		StoringStrength:SetAsync(playerUserId,HTTPService:JSONEncode(StrengthData))
	end)
	print(success,errormessage)

and see what outputs

1 Like

It sounds a bit weird but I tried printing success and errormessage but it doesn’t print it. Then I tried printing print("test") and it doesn’t print test too.

Are you testing in game? Or are you testing in the studio?

I am testing in Studio. But I think it doesn’t really matter bcs I have used Data Store in other games of mine and Data Store works in Studio too.

Try testing it in a game. I think that is the cause.

1 Like

I’d suggest you do this:

local DataStoreService = game:GetService("DataStoreService")
local StoringStrength = DataStoreService:GetDataStore("StrengthLevel")

game.Players.PlayedAdded:Connect(function(Player)

   local Skills = Instance.new("Folder")
   Skills.Name = "Skills"
   Skills.Parent = Player

   local Strength = Instance.new("Folder")
   Strength.Name = "Strength"
   Strength.Parent = Skills

   local StrengthLevel = Instance.new("IntValue")
   StrengthLevel.Name = "StrengthLevel"
   StrengthLevel.Parent = Strength
   StrengthLevel.Value = 1

   local StrengthExpLeft = Instance.new("IntValue")
   StrengthExpLeft.Name = "StrengthExpLeft"
   StrengthExpLeft.Parent = Strength
   StrengthExpLeft.Value = 100

   local StrengthCurrentExp = Instance.new("IntValue")
   StrengthCurrentExp.Name = "StrengthCurrentExp"
   StrengthCurrentExp.Parent = Strength
   StrengthCurrentExp.Value = 0

   local data = StoringStrength:GetAsync(Player.UserId)
   if data then
   Player.Strength.StrengthLevel.Value = data.StrengthLevel
   Player.Strength.StrengthExpLeft.Value = data.StrengthExpLeft
   Player.Strength.StrengthCurrentExp.Value = data.StrengthCurrentExp
   end
end)

game.Players.PlayerRemoving:Connect(function(Player)
 local data = {}
 data.StrengthLevel = Player.Strength.StrengthLevel.Value
 data.StrengthExpLeft = Player.Strength.StrengthExpLeft.Value
 data.StrengthCurrentExp = Player.Strength.StrengthCurrentExp.Value

 StoringStrength:SetAsync(Player.UserId, data)
end)

I had to edit this 2 times. Hopefully it works!

1 Like

@Comfself @dollychun Read below.

You CAN save tables to a normal datastore (not an orderedDatastore though). You do not need to convert it to a string. The reason he’s getting the error is due to the fact that he’s trying to save the actual intValue object (not the value of the intValue):

All he needs to do to fix this is simply add .Value at the end of each one:

	local StrengthData = {
		StrengthLevel = Player.Skills.Strength.StrengthLevel.Value,
		StrengthExpLeft = Player.Skills.Strength.StrengthExpLeft.Value,
		StrengthCurrentExp = Player.Skills.Strength.StrengthCurrentExp.Value
	}
1 Like

I tried adding .Value but it still has the same result.

Can you post your current script because I’ve tested your previous datastore sent in your 4th post with .Value at the end and it worked perfectly fine.