Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I don't understand why when I press buy nothing is getting added to the leaderstats coins?

Asked by 5 years ago
local MPS = game:GetService("MarketplaceService")

MPS.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == 607404806 then -- replace with your ID here
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100
        return Enum.ProductPurchaseDecision.PurchaseGranted

    elseif receiptInfo.ProductId == 607405661 then -- replace with your ID here
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end
0
I use this exact same code and it works for me so I don't know why sheepposu 561 — 5y

1 answer

Log in to vote
0
Answered by
Vxpper 101
5 years ago
Edited 5 years ago
local MPS = game:GetService("MarketplaceService")
local pid1 = 607404806
local pid2 = 607405661

MPS.ProcessReceipt = function(receiptInfo)
  for i, player in ipairs(game.Players:GetPlayers()) do
        local Coins = player.leaderstats.Coins
        if player.UserId == receiptInfo.PlayerId then   
            if receiptInfo.ProductId == pid1 then
                Coins.Value = Coins.Value + 100

            elseif receiptInfo.ProductId == pid2 then
                Coins.Value = Coins.Value + 1000

                end
            end
        end
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

This should hopefully fix your problem, I think your problem is in line 7,12. If this fixes your problem, please accept my answer. If you have any more questions comment and I will get back to you as soon as I can. Good luck scripting!

(Make sure you have a local script that prompts the players' purchase)

Ad

Answer this question