Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[RESOLVED]How to stop my developer products from processing multiple times?

Here is my developer product code:

local fiveId = 30947986
local tenId = 30948013
local twentyfiveId = 30948036
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.userId == receiptInfo.PlayerId then
			local cash = player.leaderstats.Cash
			if receiptInfo.ProductId == fiveId then
				cash.Value = cash.Value + 5000
				print(player.Name .. " purchased 5K.")
			elseif receiptInfo.ProductId == tenId then
				cash.Value = cash.Value + 10000
				print(player.Name .. " purchased 10K.")
			elseif receiptInfo.ProductId == twentyfiveId then
				cash.Value = cash.Value + 25000
				print(player.Name .. " purchased 25K.")
			end		
		end
	end
	local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
	PurchaseHistory:IncrementAsync(playerProductKey, 1)
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Right now when I buy a product it runs through the script multiple times. Buying the 5K might add 5000 to my cash one time but then buy it again and it might add 15000 or 20000.

I bought the 10k one and the output was: Player purchased 10K. Player purchased 10K. Player purchased 10K. Player purchased 10K. Player purchased 10K. Player purchased 25K.

4 comments

0

Add a debounce, cause it's running it more than once sometimes.

0

Is there anything in the output?

0

And how can they add random amounts of cash? It's impossible, it can only add any one of the amounts you defined.

0

@NinjoOnline @TheDeadlyPanther It is running multiple times, I added a print line in there and it's repeated over and over in the output when it runs. I tried adding a debounce but the script just stopped working.

1 answer

Looks like it's working now, all I changed was: local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId to local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId since it was too long.

This discussion is preserved as it was. New answers, comments, and votes are closed.