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)
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.
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
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?
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.
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
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)