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

How do I keep a DevProduct from giving out benefits after used?

Say I have a product that gives you 500 cash. I use to cash to purchase an in-game item. But when you come back on, you have 500 cash again.

local MarketPlace = game:GetService("MarketplaceService")
local DataStore = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local ProductID = 22492584
MarketPlace.ProcessReceipt = function(ReceiptInfo)
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.userId == ReceiptInfo.PlayerId then
			if ReceiptInfo.ProductId == ProductID then
				player.Cash.Value = player.Cash.Value + 500
			end
		end
	end
local playerProductKey = "player_" .. ReceiptInfo.PlayerId .. "_purchase_" .. ReceiptInfo.PurchaseId
DataStore:IncrementAsync(playerProductKey, 1)
return Enum.ProductPurchaseDecision.PurchaseGrant
end

2 comments

0

Simply use game passes?

0

Oh sorry , I misread the thing.

1 answer

✓ Accepted answer

You're returning PurchaseGrant, not PurchaseGranted.

**Edit: ** Though to answer the main question here (despite it being somewhat unneeded) -

If you wanted to make sure that you weren't awarding something twice you could add the receipt's PurchaseId to a 'DataStore' after the player is given what they've purchased.

PurchaseId is a unique identifier for a purchase, meaning that you would add an if statement to see whether that PurchaseId has already been used. If it had, simply return PurchaseGranted. If it hadn't continue on with awarding the item.

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