How to do different things for dev products in same script?

I want to do different things with my dev products when you buy them and I am having a hard time doing that. I have all the dev products and their functions in one script.

local MarketPlaceService = game:GetService(“MarketplaceService”)
local repstorage = game:GetService(“ReplicatedStorage”)
local players = game:GetService(“Players”)
local flush2 = 1219436157
local flush5 = 1219436221
local flush10 = 1219436267
local flush50 = 1219436320
local flush1k = 1219436357

local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)

if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end

if player then
if(tonumber(receiptInfo.ProductId) == flush2) then
wait(2)
repstorage.Robux:Clone().Parent = workspace
end

  if(tonumber(receiptInfo.ProductId) == flush5) then
  	wait(2)
  	repstorage.Robux:Clone().Parent = workspace
  	wait()
  	repstorage.Robux:Clone().Parent = workspace
  end
  
  if(tonumber(receiptInfo.ProductId) == flush10) then
  	wait(2)
  	repstorage.Robux:Clone().Parent = workspace
  	wait()
  	repstorage.Robux:Clone().Parent = workspace
  	wait()
  	repstorage.Robux:Clone().Parent = workspace
  end
  
  if(tonumber(receiptInfo.ProductId) == flush50) then
  	wait(2)
  	repstorage.Robux50:Clone().Parent = workspace
  end
  
  if(tonumber(receiptInfo.ProductId) == flush1k) then
  	wait(2)
  	repstorage.Robux1k:Clone().Parent = workspace
  end

end
end

MarketPlaceService.ProcessReceipt = processReceipt

This is my script and whenever you buy a dev product and then another, it does the thing for the dev product and everything else/the other dev products functions you bought before it, even though you are only buying one dev product at a time. It may sound confusing but I hope there is someone that can help me.

2 Likes

You need to return Enum.ProductPurchaseDecision.PurchaseGranted after processing their purchase, otherwise the function will be run again until PurchaseGranted is returned.

3 Likes
local MarketPlaceService = game:GetService("MarketplaceService")
local storage = game:GetService("ReplicatedStorage")
local robux = storage:WaitForChild("Robux")
local robux50 = storage:WaitForChild("Robux50")
local robux1k = storage:WaitForChild("Robux1k")
local players = game:GetService("Players")
local flush2 = 1219436157
local flush5 = 1219436221
local flush10 = 1219436267
local flush50 = 1219436320
local flush1k = 1219436357

local function processReceipt(receiptInfo)
	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if player then
		if receiptInfo.ProductId == flush2 then
			task.wait(1)
			robux:Clone().Parent = workspace
			return Enum.ProductPurchaseDecision.PurchaseGranted

		elseif receiptInfo.ProductId == flush5 then
			task.wait(1)
			robux:Clone().Parent = workspace
			task.wait(1)
			robux:Clone().Parent = workspace
			return Enum.ProductPurchaseDecision.PurchaseGranted

		elseif receiptInfo.ProductId == flush10 then
			task.wait(1)
			robux:Clone().Parent = workspace
			task.wait(1)
			robux:Clone().Parent = workspace
			task.wait(1)
			robux:Clone().Parent = workspace
			return Enum.ProductPurchaseDecision.PurchaseGranted

		elseif receiptInfo.ProductId == flush50 then
			task.wait(1)
			robux50:Clone().Parent = workspace
			return Enum.ProductPurchaseDecision.PurchaseGranted

		elseif receiptInfo.ProductId == flush1k then
			task.wait(1)
			robux1k:Clone().Parent = workspace
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end
end

MarketPlaceService.ProcessReceipt = processReceipt
1 Like