(HELP) Too many DataStore Requests error!

For some reason, this script works in Studio, but there’s some infinite yield where it can’t return the requests correctly. I just don’t know where. Whenever you purchase any developer product in game, it just adds it to the DataStore queue, and send the infinite requests.

function processReceipt(info)
	local plr = game:GetService("Players"):GetPlayerByUserId(info.PlayerId)

	if plr then
		if info.ProductId == 1728120559 then
			-- Logic for product with ID 1728120559
			plr.Character.Humanoid.Health = 0
			local stats = plr:WaitForChild("leaderstats")
			local changeStage = stats and stats:FindFirstChild("Stage")
			if changeStage then
				changeStage.Value +=1
				script.Value.Value = true
			end
			
		elseif info.ProductId == 1729065465 then
			-- Logic for product with ID 1729065465
			plr:WaitForChild("leaderstats").Coins.Value = plr.leaderstats.Coins.Value + 25
			plr.Character.Humanoid.Health = 100
			game.ReplicatedStorage.PurchaseGood:FireClient(plr)
			if script.Value.Value == true then
				print("yay")
			end
		elseif info.ProductId == 1729065464 then
			-- Logic for product with ID 1729065464
			plr:WaitForChild("leaderstats").Coins.Value = plr.leaderstats.Coins.Value + 50
			plr.Character.Humanoid.Health = 100
			game.ReplicatedStorage.PurchaseGood:FireClient(plr)
			if script.Value.Value == true then
				print("yay")
				end
		elseif info.ProductId == 1729065463 then
			-- Logic for product with ID 1729065463
			plr:WaitForChild("leaderstats").Coins.Value = plr.leaderstats.Coins.Value + 125
			plr.Character.Humanoid.Health = 100
			game.ReplicatedStorage.PurchaseGood:FireClient(plr)
				if script.Value.Value == true then
					print("yay")
					end
		elseif info.ProductId == 1729065466 then
			-- Logic for product with ID 1729065466
			plr:WaitForChild("leaderstats").Coins.Value = plr.leaderstats.Coins.Value + 250
			plr.Character.Humanoid.Health = 100
			game.ReplicatedStorage.PurchaseGood:FireClient(plr)
					if script.Value.Value == true then
				print("yay")
						end
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
		else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

game:GetService("MarketplaceService").ProcessReceipt = processReceipt

I need some help with organizing the script for where to put the “return true” at, in order for the first part of the script to work. (By that I mean the first developer product in the script). With the return true, the number of stage points added with twofold each time, when I’d like it to add by one. Thanks!

3 Likes

Is the output printing out ‘yay’? I don’t understand if the request doesn’t work or if it’s running twice.

Are you using datastore2 as your system?

I just deleted the print “yay” part, since my script no longer requires that system. It was an old system that I put in that used a boolvalue. However, the script works in studio, but not in game.

What do you mean by datastore2?

it’s a better version of datastores that’s a community project - really novel, go check it out!

I’m still getting the error after installing datastore2. It’s really bugging me! I tried to add wait increments, but that doesn’t seem to fix it. Thanks for giving the info though!

Can you show a screenshot of the error? I’m having trouble picturing it.
As for ordering the script, you should probably use the one on the Creator Documentation. It uses a table for each product.

Small example:

local mps = game:GetService("MarketplaceService")
local productFunctions = {}


productFunctions[productID] = function(receipt, player)
    --benefits
    return true
end

local function processReceipt(info)
    local player = game.Players:GetPlayerByUserId(info.PlayerId)
    local productId = info.ProductId
    local handler = productFunction(productId)
    local success, result = pcall(handler, info, player)
    if success then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    else
        warn(result)
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end
end

mps.ProcessReceipt = processReceipt

If you click here and scroll down a bit, you can find the full handling script.

1 Like

So what was the error, exact wording?
Was it:
DataStore request was added to queue. If queue fills, further requests will be dropped. Try sending fewer requests.
Or was it a different error?

1 Like

It was that error. Sorry I forgot to paste it. Also, I get the warning that the queue filled up too much after that.

1 Like

Oh, and forget that reply where I sent the script. I accidentally sent in a different script

function processReceipt(info)
	local plr = game:GetService("Players"):GetPlayerByUserId(info.PlayerId)

	if plr then
		if info.ProductId == 1728120559 then
			wait()
			local stats = plr.leaderstats
			local changeStage = stats and stats:FindFirstChild("Stage")
			if changeStage then
				changeStage.Value = changeStage.Value +1
				script.Value.Value = true
				wait(0.25)
				plr.Character.Humanoid.Health = 0
			end
			return Enum.ProductPurchaseDecision.PurchaseGranted
		elseif info.ProductId == 1729065465 then			
			plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 25
			plr.Character.Humanoid.Health = 100
			game.ReplicatedStorage.PurchaseGood:FireClient(plr)
			return Enum.ProductPurchaseDecision.PurchaseGranted
		elseif info.ProductId == 1729065464 then
			plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 50
			plr.Character.Humanoid.Health = 100
			game.ReplicatedStorage.PurchaseGood:FireClient(plr)
			return Enum.ProductPurchaseDecision.PurchaseGranted
		elseif info.ProductId == 1729065463 then
			plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 125
			plr.Character.Humanoid.Health = 100
			game.ReplicatedStorage.PurchaseGood:FireClient(plr)
			return Enum.ProductPurchaseDecision.PurchaseGranted
		elseif info.ProductId == 1729065466 then
			plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 250
			plr.Character.Humanoid.Health = 100
			game.ReplicatedStorage.PurchaseGood:FireClient(plr)
			return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
		end
	

game:GetService("MarketplaceService").ProcessReceipt = processReceipt

Could you also add the part of the script that accesses the DataStore? If this is a different script, I’ll probably need to see that too before I can help any more.

Here is the checkpoint script, which also hosts the datastore.

local DataStoreService = game:GetService(“DataStoreService”)
local PlayerDataStore = DataStoreService:GetDataStore(“PlayerDataStore”)
local Players = game:GetService(“Players”)
local Workspace = game:GetService(“Workspace”)

local DataStoreService = game:GetService(“DataStoreService”)
local PlayerDataStore = DataStoreService:GetDataStore(“PlayerDataStore”)
local Players = game:GetService(“Players”)
local Workspace = game:GetService(“Workspace”)

Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild(“leaderstats”)

if not leaderstats then
	leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local values = {"Wins", "Stage", "Coins"}
	for _, valueName in ipairs(values) do
		local value = Instance.new("IntValue")
		value.Name = valueName
		value.Parent = leaderstats
	end
end

local success, errorMsg = pcall(function()
	local playerData = PlayerDataStore:GetAsync(tostring(player.UserId)) or {}
	player.leaderstats.Stage.Value = playerData.Stage or 1
	player.leaderstats.Wins.Value = playerData.Wins or 0
	player.leaderstats.Coins.Value = playerData.Coins or 0
end)
if success then
	print("Successfully loaded " .. player.Name .. "'s data")
	plrToStage(player)
else
	warn(errorMsg)
end
-- This is how we connect to the player respawning (Death/Reset/Etc...)
player.CharacterAdded:Connect(function()
	plrToStage(player)
end)

end)

function plrToStage(plr)
repeat wait() until plr.Character and plr.Character:FindFirstChild(“HumanoidRootPart”)

local stagePart = game.Workspace.checkpoints:FindFirstChild(tostring(plr.leaderstats.Stage.Value))
if not stagePart then
	print("Could not find stage part for checkpoint " .. tostring(plr.leaderstats.Stage.Value))
	return
end

plr.Character:WaitForChild("HumanoidRootPart").CFrame = stagePart.CFrame + Vector3.new(0, 0, 0)

end

Players.PlayerRemoving:Connect(function(player)
local success, errorMsg = pcall(function()
local playerData = {
Stage = player.leaderstats.Stage.Value,
Wins = player.leaderstats.Wins.Value,
Coins = player.leaderstats.Coins.Value
}
PlayerDataStore:SetAsync(tostring(player.UserId), playerData)
print("Successfully saved " … player.Name … “'s data”)
end)

if not success then
	warn(errorMsg)
end

end)

for _, checkpoint in pairs(game.Workspace.checkpoints:GetChildren()) do
checkpoint.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)

		local checkpointNumber = tonumber(checkpoint.Name)
		
		if player.leaderstats.Stage.Value < checkpointNumber then
			player.leaderstats.Stage.Value = checkpointNumber
			
			game.Workspace.SoundEffects.Coin:Play()
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value +5
		end
	end
end)

end

It might be to do with the products script - it is coded in such a way that it will only return Enum.ProductPurchaseDecision.NotProcessedYet if the product ID isn’t registered, and it won’t return that if the code didn’t execute successfully. I would strongly recommend using the script on the creator documentation.

Also, is this error only happening with the products script? I don’t see anywhere you have told it to save data within the products script.

local productFunctions = {}

productFunctions[exampleId] = function(receipt, player)
    --benefits
    --return 'true' for it to register properly
    return true
end

local function processReceipt(info)
    local player = game.Players:GetPlayerByUserId(info.PlayerId)
    local product = info.ProductId
    local handler = productFunctions(product)
    local success, result = pcall(handler, info, player)
    if success then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    else
        warn(result)
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end
end

game.MarketplaceService.ProcessReceipt = processReceipt

I’lll try that, just I’m not sure that the Roblox script isn’t meant to host multiple developer products that are for the same currency

This would replace the script you currently have - disable that one and use this one. Also, make sure that the MarketplaceSerice.ProcessReceipt = processReceipt is ONLY being used ONCE, in ONE server-side script.

And yes, this script format can handle multiple developer products that are for the same currency. I have used this script before - with different products that add to the same value.

I edited the script so I wouldn’t get an error. It still works in studio, but not in-game. I’m not really sure of what else to do, then maybe rewrite the whole datastore or something.

local productFunctions = {}

productFunctions[1728120559] = function(receipt, player)
			wait()
			local stats = player.leaderstats
			local changeStage = stats and stats:FindFirstChild("Stage")
			if changeStage then
				changeStage.Value = changeStage.Value +1
				script.Value.Value = true
				wait(0.25)
				player.Character.Humanoid.Health = 0
				return true
			end
			end
			
productFunctions[1729065465] = function(receipt, player)
	local stats1 = player.leaderstats.Coins
		stats1.Value = stats1.Value +1
		player.Character.Humanoid.Health = 100
	return true
	end

local function processReceipt(info)
	local player = game.Players:GetPlayerByUserId(info.PlayerId)
	local product = info.ProductId
	local handler = productFunctions[product]
	local success, result = pcall(handler, info, player)
	if success then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		warn(result)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

game.MarketplaceService.ProcessReceipt = processReceipt

Are there any errors when you try it in-game?

Still the same one, that it added it to the DataStore queue.