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

Trying to use a DevProduct to give a player Credits, what can I do to fix this script?

local MarketplaceService=game:GetService("MarketplaceService")
local devproductid=52874408
MarketplaceService.ProcessReceipt = function(receiptInfo)
	for i,player in ipairs(game.Players:GetChildren()) do
		if receiptInfo.ProductId == devproductid then
		player.Credits.Value = player.Credits.Value + 100
		end
		end
return Enum.ProductPurchaseDecision.PurchaseGranted
	end

This is supposed to give 100 credits to the player, however, when tested in the actual game it doesn't give the player credits. It works in normal mode however

1 comment

0

Heads up; You don't check the playerId, just the ProductId, wich means every player will get credits instead of the player that purchase it.

1 answer

✓ Accepted answer

Here is a dev product script that you can use for any dev product you just have to change what should be done if all requirements are met. I've edited it to suit your needs so you can just copy and paste it but i do suggest you go through it and see what does what and why it's suppose to be that way

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 52874408


	MarketplaceService.ProcessReceipt = function(receiptInfo) 
 
	for i, player in ipairs(game.Players:GetChildren()) do

		if player.userId == receiptInfo.PlayerId then
 
			if receiptInfo.ProductId == productId then
 
 			player.Credits.Value = player.Credits.Value + 100
			end
		end
	end	
 
	local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
	ds:IncrementAsync(playerProductKey, 1)	
 
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end

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