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

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

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

1 comment

0

I use this exact same code and it works for me so I don't know why

1 answer

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)

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