Buy coins script not functioning properly

I tryed to make a buy coins script but it takes the robux but does not add any coins to it.

The localscript:

--1235674804

local mps = game:GetService("MarketplaceService")

local player = game.Players.LocalPlayer

local id = 1238799050

script.Parent.MouseButton1Click:Connect(function()

mps:PromptProductPurchase(player, id)

end)

(this localscript is present in all 6 textbutton but with different ID)

The script inside serverscriptservice:

local mps = game:GetService("MarketplaceService")
--Buy coins ID for Thug
local ThugId = 1238799050
local ThugId2 = 1238799103
local ThugId3 = 1238799148
local ThugId4 = 1238799188
local ThugId5 = 1238799257
local ThugId6 = 1238799316

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

	if not  player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if player then local Crowns = player.leaderstats.Crowns

		if receiptInfo.ProductId == ThugId then
			Crowns.Value += 100
		end

		if receiptInfo.ProductId == ThugId2 then
			Crowns.Value += 200
		end

		if receiptInfo.ProductId == ThugId3 then
			Crowns.Value += 300
		end
		
		if receiptInfo.ProductId == ThugId4 then
			Crowns.Value += 500
		end
		
		if receiptInfo.ProductId == ThugId5 then
			Crowns.Value += 1000
		end
		
		if receiptInfo.ProductId == ThugId6 then
			Crowns.Value += 50000
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end
mps.ProcessReceipt = processReceipt

Thanks in advance for helping me :slight_smile:

Try this:

local mps = game:GetService("MarketplaceService")
local Table = {
	[1238799050] = 100,
	[1238799103] = 200,
	[1238799148] = 300,
	[1238799188] = 500,
	[1238799257] = 1000,
	[1238799316] = 50000
}

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

	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if player then 
		local Crowns = player.leaderstats.Crowns

		if Table[receiptInfo.ProductId] then
			Crowns.Value += Table[receiptInfo.ProductId]
		end
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end
mps.ProcessReceipt = processReceipt
2 Likes

Oh ok so your using table to do so. Then you get variables from the table to do so. Thanks for the script

But actually not working again. I don’t know why its not working

What doesn’t work? Did you try adding prints? Is there an error in the output?

1 Like

Ya let me check that real quick and let you know

Oh sorry its not a problem from your script. Some leaderstats problem with mines. Sorry for telling like that. Your script just works fine