How Can I Tell If The Player Actually Bought The Product?

So whenever a player is prompted to buy something I want to know if they actually bought the product then I’d fire an event. here’s the script

local MarketPlaceService = game:GetService("MarketplaceService")
local id = 1265665801

script.Parent.MouseButton1Click:Connect(function()
	MarketPlaceService:PromptProductPurchase(script.Parent.Parent.Parent.Parent.Parent, id)
end)
4 Likes

You can check if the player bought it via the isPurchased boolean on the PromptProductPurchaseFinished to find out if the player bought it.

local MarketPlaceService = game:GetService("MarketplaceService")
local id = 1265665801

script.Parent.MouseButton1Click:Connect(function()
	MarketPlaceService:PromptProductPurchase(script.Parent.Parent.Parent.Parent.Parent, id)
end)

MarketPlaceService.PromptProductPurchaseFinished:Connect(function(PlayerId, GamepassId, IsPurchased)
       if IsPurchased == Enum.ProductPurchaseDecision.PurchaseGranted then -- if this line errors try putting true instead of the enum
                -- your code here
      end
end)

I don’t know if this script really works as I just wrote it here and didn’t test it out, but it should.

4 Likes

Not only that, also call a pcall(), so if there is an error the script wouldn’t stop.

local success, errormessage = pcall(function()
  MarketPlaceService.PromptProductPurchaseFinished:Connect(function(PlayerId, GamepassId, IsPurchased)
       if IsPurchased == Enum.ProductPurchaseDecision.PurchaseGranted then
         -- your code here
      end
  end)
end)

if not success then
  print("uh oh it failed...error:", errormessage)
end
3 Likes

My bad, I forgot about those.

maxchars

2 Likes

So should it be working in studio with their test? Because it’s not working with a basic print “Player succesfully bought product” Should I test in game?

Let me check @AranhaDev’s code real quick, don’t test it in-game.

2 Likes
local success, errormessage = pcall(function()
	MarketPlaceService.PromptPurchaseFinished:Connect(function(player, assetid, isPurchased)
		if isPurchased == true then
			-- put the rest of your code here!
		end
	end)
end)

this is better


isPurchased doesn’t return an Enum value, it only returns a boolean value so that is why it didn’t work.

1 Like

Basic print still won’t work in studio shall I test it in game now? No errors in output

Can I see your code?

CLASSIC ROBLOX WITH THEIR LIMIT

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketPlaceService = game:GetService("MarketplaceService")

local id = 1265665801

script.Parent.MouseButton1Click:Connect(function()
	MarketPlaceService:PromptProductPurchase(script.Parent.Parent.Parent.Parent.Parent, id)
end)

local success, errormessage = pcall(function()
	MarketPlaceService.PromptPurchaseFinished:Connect(function(player, assetid, isPurchased)
		if isPurchased == true then
			print("Purchase Succesful")
		end
	end)
end)

ignore replicated storage ill be using that for a remote event

You need fill something in for the assetid arguement.

1 Like

Why can’t you use game:GetService("Players").LocalPlayer instead of script.Parent.Parent.Parent.Parent.Parent?

should I just change it to the id value?

yes

limitlimitlimit again sorrt

I made this script about a year ago lol it was off a tutorial

1 Like

Is the thing you’re trying to sell a dev product?
If so, you might wanna use PromptProductPurchaseFinished instead of PromptPurchaseFinished (because roblox wants you to)

3 Likes

you just saved me lol appreciate you and @coolifysz my bad for not clearly stating it’s a dev product but thanks you helped alot!

1 Like

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