Buy coins Script not working

I tried making a Buy coins UI script but it does not work

It takes the robux but it does not add the money.

Script inside the text button:

local mps = game:GetService("MarketplaceService")

local player = game.Players.LocalPlayer

local id = 1236310652

script.Parent.MouseButton1Click:Connect(function()

mps:PromptProductPurchase(player, id)

end)

The script inside serverscriptservice:

local mps = game:GetService("MarketplaceService")
local id = 1236309956
local id2 =1236310540 
local id3 = 1236310652

local function processReciept(receiptInfo)

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

	if not  player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if player then
		if receiptInfo.ProductId == id then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
		end

		if receiptInfo.ProductId == id2 then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100
		end

		if receiptInfo.ProductId == id3 then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end


end

I tried for 5 days to make this work but it does not seem to
Leaderstats value:

You never set the ProcessReceipt function (MarketPlaceService) to the function you created.

Simply add this line to your code (SERVER).

mps.ProcessReceipt = processReciept
2 Likes

Below which line exactly, Actually I am new to all of this Developer products so I dont where to put this line

You can put it at the end of the server script, under everything else.

2 Likes

Ok thanks for understanding. I am really helpful to you as this was taking so long figure out

1 Like

No worries. Let me know if you need any further help.

1 Like
local mps = game:GetService("MarketplaceService")
local id = 1236309956
local id2 =1236310540 
local id3 = 1236310652

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

	if not  player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if player then
		if receiptInfo.ProductId == id then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
		end

		if receiptInfo.ProductId == id2 then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100
		end

		if receiptInfo.ProductId == id3 then
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end


end
mps.ProcessReceipt = processReciept

Is this script correct?

Yes, it is. I would like to simplify some things though, just to make it easier to modify. I suggest using this one :slight_smile:

local mps = game:GetService("MarketplaceService")
local id = 1236309956
local id2 =1236310540 
local id3 = 1236310652

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

	if not  player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if player then local coins = player.leaderstats.Coins
		if receiptInfo.ProductId == id then
			coins.Value += 10
		end

		if receiptInfo.ProductId == id2 then
			coins.Value += 100
		end

		if receiptInfo.ProductId == id3 then
			coins.Value += 1000
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end
mps.ProcessReceipt = processReceipt
1 Like

Let me know if that solves your issue.

1 Like

Omg, Very thank you for sending this script!

No problem. If that fully solved your issue, make sure to mark the post as solved. Have a good day/night.

1 Like

OMG! Thank you so much for helping me. I really wanted fast help as this was for a commission. Thank you so much!!!. You to sure and definitely have a good day/night

1 Like
local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local coinProducts = {[1236309956] = 10, [1236310540] = 100, [1236310652] = 1000}

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

	if not  player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if player then		
		if coinProducts[receiptInfo.ProductId] then
			player.leaderstats.Coins.Value += coinProducts[receiptInfo.ProductId]
		end
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

mps.ProcessReceipt = processReceipt
1 Like

Thanks for this too but I already got the solution from @Volieb. But anyways thank you