Unable to cast value to object for prompt product purchase

I want to achieve when pressing a UIButton a product prompt appears and you can buy the developer product.

I have tried to change the ID, and I have checked the forums but have not found anything.

Down below is the LUA code, is there any errors shown? Did I do something wrong.

ContentSF_Money.TenThousand.MouseButton1Up:Connect(function(plr)
	MarketplaceService:PromptProductPurchase(plr, TenThousandID)
	
	if MarketplaceService.PromptPurchaseFinished then
		Money = Money.Value + 10000
	end
end)

Do this instead:

Money.Value += 10000

Or

Money.Value = Money.Value + 10000

There error still occurs.

That’s strange… What is the variable “Money” and what type of instance is it?

Without the value adding part of the script, the error still occurs. Does it have something to do with the prompting part of the script? It is a int value btw.

Is that the full script?

local script:

ContentSF_Money.TenThousand.MouseButton1Up:Connect(function(plr)
	MarketplaceService:PromptProductPurchase(plr, TenThousandID)
end)

server script:

game:GetService("MarketplaceService").PromptProductPurchaseFinished:Connect(function(uid, pid, success)
	if success then
		local plr = game.Players:GetPlayerByUserId(uid)
		if pid == TenThousandID then
			plr.leaderstats.Money.Value+=10000
		end
	end
end)

this is how to correctly add money to a leaderstat if the player purchases a dev product

Use ProcessReceipt instead

it works thesame if you check the purchased parameter

Even with the code below in a local script, it still prints the error

ContentSF_Money.TenThousand.MouseButton1Up:Connect(function(plr)
	MarketplaceService:PromptProductPurchase(plr, TenThousandID)
end)

You should still use ProcessReceipt

Here is the proper way:

Server script:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local TenThousandID = put your id here

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)

	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if receiptInfo.ProductId == TenThousandID then
		player.leaderstats.Money.Value += 10000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

Local script:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local TenThousandID = put your id here

local localPlayer = Players.LocalPlayer

ContentSF_Money.TenThousand.MouseButton1Up:Connect(function()
	MarketplaceService:PromptProductPurchase(localPlayer, TenThousandID)
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.