How to know if a player has bought a developer product

You can see the documentation for ProcessReceipt here


You don’t check the enumeration, you have to return the enumeration as stated in the documentation page. You can do something like this:

local MPS = game:GetService("MarketplaceService")

function MPS.ProcessReceipt(receiptInfo)
    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)

    if player then
        player.leaderstats.Coinn.Value = player.leaderstats.Coin.Value + 100
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end

    return Enum.ProductPurchaseDecision.NotProcessedYet
end
2 Likes

Still won’t work. I tried using your script. It prompted me to buy something, like I had scripted earlier, but it didn’t do anything.

Edited post. Use @Rare_tendo’s example instead

1 Like

Didn’t work. Just to be more clear, if something was completely out of line, here is the script that I have right now:

local MarketPlaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local id = "1006738178"
script.Parent.MouseButton1Click:Connect(function()
game.MarketplaceService:PromptProductPurchase(player, id)
end)
local MPS = game:GetService("MarketplaceService")

function MPS.ProcessReceipt(receiptInfo)
    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)

    if player then
        player.leaderstats.Coinn.Value = player.leaderstats.Coin.Value + 100
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end

    return Enum.ProductPurchaseDecision.NotProcessedYet
end

The code I posted should be in a server (normal) script in ServerScriptService

1 Like

I tried putting your script in serverscriptservice. It still did not work. Why?

Check your output for any error messages

1 Like

Could not find any errors regarding the script.

Sorry for such a late reply
Normal script inside ServerScriptService
–Read over the script and change the ’ ’ for your case

local MarketPlaceService = game:GetService("MarketplaceService")
local product = 'id of the product'

local function processReceipt(receiptInfo)
	if receiptInfo.ProductId == product then
		local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	player.leaderstats.'your leaderstat here'.Value = player.leaderstats.'your leaderstat here'.Value + 'value you want to add'
	return Enum.ProductPurchaseDecision.PurchaseGranted
   end
end
MarketPlaceService.ProcessReceipt = processReceipt

And this is what you should have inside a LocalScript inside your button

local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local productId = 'your product id'
script.Parent.MouseButton1Down:Connect(function(promptPurchase)
	local player = Players.LocalPlayer
	MarketPlaceService:PromptProductPurchase(player, productId)
end)

If you want to add more DevProducts then you would just add an if… to the function under the first end

5 Likes

Put a RemoteEvent in replicatedstorage called Buy1Coin.

Put a localscript in the button

script.Parent.MouseButton1Down:Connect(function()
game.ReplicatedStorage:WaitForChild("Buy1Coin"):FireServer()
end)

Put a Script in ServerScriptService

local mkp = game:GetService("MarketplaceService")

mkp.PromptProductPurchaseFinished:Connect(function(userId,product,purchased)
local player = game.Players:GetPlayerByUserId(userId)
if purchased then
player.leaderstats.Coinn.Value = player.leaderstats.Coinn.Value +1
end
end)

game.ReplicatedStorage:WaitForChild("Buy1Coin").OnServerEvent:Connect(function(player)
mkp:PromptProductPurchase(player,1006738178)
end)
8 Likes