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

Why isn't my purchase script adding to leaderstats?

Hello!

I have re-written my script a bit and am still have issues w/it working. I am trying to add +1 to the customers leaderstat any time they purchase a clothing item from my home store, I have this as a server script:

local mps = game:GetService("MarketplaceService")

mps.ProcessReceipt = function(receiptInfo)
   local Player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
   if receiptInfo.ProductId == 1234546 then
        Player.leaderstats.Purchases.Value = Player.leaderstats.Purchases.Value + 1
        return Enum.ProductPurchaseDecision.PurchaseGranted
   elseif receiptInfo.ProductId == 12345467 then
        Player.leaderstats.Purchases.Value = Player.leaderstats.Purchases.Value + 1
        return Enum.ProductPurchaseDecision.PurchaseGranted
  
   end
end

I used "123456" and "1234567" as placeholders, I would put the actual ID of the item there in game.

I have a basic leaderstat script:

game.Players.PlayerAdded:Connect(function(plr)
    local Stats = Instance.new('Folder') 
    Stats.Name = 'leaderstats'
    Stats.Parent = plr

    local Purchases = Instance.new('IntValue')
    Purchases.Name = 'Purchases'
    Purchases.Value = 0
    Purchases.Parent = Stats


end)

Any suggestions or thoughts as to why this is not working?

1 comment

0

ProcessReceipt only works with Developer Products.

2 answers

✓ Accepted answer

Hello!

Like the two people above me said, ProcessReceipt works with Developer Products, not clothing. Do you have an example code from when you're selling the clothing? I'm guessing it would look similar to this:

local sell = script.Parent
local Item = 4825559312 --ID of product

local Click = Instance.new("ClickDetector",sell)

Click.MouseClick:connect(function(p)
	game:GetService("MarketplaceService"):PromptPurchase(p,item)
end)

Check out this page! :)

https://developer.roblox.com/en-us/api-reference/function/MarketplaceService/PlayerOwnsAsset

Hope this helps

ProcessReceipt only works with Developer Products.

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