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

How do I make a developer product that gives the player value?

local mpService = game:getService("MarketplaceService")

mpService.ProcessReceipt = function(purchaseInfo)
    local plr = game:getService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId)
    if purchaseInfo.ProductId ==  335171701 then
	player.leaderstats.Power.Value = player.leaderstats.Power.Value + 100
        
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

There is my code, but it won't actually add anything to the leaderboard.

1 answer

I used ipairs as it returns the function, table and int value. This loops through players for receipt info, if the receiptinfo matches the player user.id and the product matches the devprodcutId then the leaderstats Power.Value is increased.

	local MarketplaceService = game:GetService('MarketplaceService')
	local devproductId = 335171701 -- The ID of the dev product.
	 
	MarketplaceService.ProcessReceipt = function(receiptInfo)
	    for i, player in ipairs(game.Players:GetChildren()) do
	        if player.userId == receiptInfo.PlayerId then
	            if receiptInfo.ProductId == devproductId then
	 
	                -- Receive money
	                player.leaderstats.Power.Value = player.leaderstats.Power.Value + 100
	            end
	        end
	    end
	    return Enum.ProductPurchasedDescision.PurchaseGranted
	end

1 comment

1

or just use receiptInfo.PlayerId

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