Buying Coins with robux

So I made a script, and I need it to do something. Heres the script.

button.MouseButton1Down:Connect(function()

end)

Now, inside there, I need it to prompt to buy a certain Developer Product, not gamepass.
I then need it to make sure they actually bought it, and then give them the coins.

I am not sure how to prompt Developer Products. Is it the same as gamepasses? And how do I check that they bought it?

All help is appreciated, thanks yall!

1 Like

https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

1 Like
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local productID = 0000000  -- Change this to your developer product ID
 
-- Function to prompt purchase of the developer product
local function promptPurchase()
	local player = Players.LocalPlayer
	MarketplaceService:PromptProductPurchase(player, productID)
end
2 Likes

The Local Script to prompt the devProduct Purchase can be set like this

local Player = game.Players.LocalPlayer
local MarketPlaceService = game:GetService("MarketplaceService")

local DevProductID = script.Parent.DevProductID.Value
local PurchaseButton = script.Parent

PurchaseButton.MouseButton1Click:Connect(function()
	MarketPlaceService:PromptProductPurchase(Player, DevProductID)
end)

You can have a value inside the buy button like me or just put the value its self on “local DevProductID = script.Parent.DevProductID.Value” and then use the MarketPlaceService and Promt the product purchase.

Not true. All you need to do to make this compatible to his script is

PurchaseButton.MouseButton1Click:Connect(function()
	promptPurchase()
end)

As you can see I get the localPlayer. Read the script properly :

1 Like

Sorry I did not see that :man_facepalming:

2 Likes

Its all good mate. It was hard to spot :rofl:

2 Likes

Ok so I am back from my holiday, so I just put this into a script (or a localscript?) and then I say

script.Parent.MouseButton1Down:connect(function()
promptPurchace()
end)

I also cant make the game now for 7 days, was falsely banned of roblox for a week, Ill just suck it up.

Local Script. (Character Requirements)

so now that its prompted it, how do I check if they have actuallly clicked “Buy” and give them their coins

so i prompted the purchace, it said something went wrong but still gave me the coins when I never paid…

1 Like

Show me what It said went wrong.

ProcessReceipt gets called when the player purchases the product so if you have that defined then it’s already handled for you. If you have a client-side effect that’s dependent on the prompt being closed then you can use PromptProductPurchaseFinished, but NEVER USE IT TO HANDLE PRODUCT PURCHASES. ProcessReceipt has special requirements to successfully process a product purchase (returning a ProductPurchaseDecision enum).

when I clicked the gui to prompt purchace it said that something went wrong, so it never bought it but still gave me coins

I like to keep mine like this:
It has a IntValue inside the button and the IntValue is the Dev Product Id.

local Player = game.Players.LocalPlayer
local MarketPlaceService = game:GetService("MarketplaceService")
local DevProductID = script.Parent.DevProductID.Value
local PurchaseButton = script.Parent

PurchaseButton.MouseButton1Click:Connect(function()
MarketPlaceService:PromptProductPurchase(Player, DevProductID)
end)

And can I see your script on how you give the player coins?

so its not the official “coins” variable, just a test script to see if it adds it.
local coins = 0

PromptPurchase() – the prompt purchase function

and once it prompts the purchase it adds 100 coins
coins = coins +100

Screen Shot 2021-07-06 at 11.05.53 am
the error so uh this is what it says