I’m making a donation gui and I wanted to add a loading screen when a player chooses to purchase
I wanted to detect if the player cancels or purchases the product.
local function setUp(inst,devID)
inst.MouseButton1Click:Connect(function()
MPS:PromptProductPurchase(plr, devID)
tween:Play() -- fade in tween
end)
MPS.PromptPurchaseFinished:Connect(function(plr, assetID, bool) -- doesn't work :(
if bool then
print("buy")
done:Play() -- fade out tween
else
print("cancel")
done:Play()
end
end)
end
local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
if isPurchased then
print(player.Name .. " bought an item with AssetID: " .. assetId)
else
print(player.Name .. " didn't buy an item with AssetID: " .. assetId)
end
end)
if you add this in a server script then everytime a player makes a purchase inside your game, the function would run. so you need to put it in a server script then handle the tweening in the server side by player.PlayerGui.YourGui or use a remote event.
can you try doing this and see if it would print pass?
local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
print("pass")
if isPurchased then
print(player.Name .. " bought an item with AssetID: " .. assetId)
else
print(player.Name .. " didn't buy an item with AssetID: " .. assetId)
end
end)
oh, if you want to make something for devproducts do this
local prodId = 1
MarketplaceService.ProcessReceipt = function(receiptInfo)
-- find the player based on the PlayerId in receiptInfo
for i, player in ipairs(game.Players:GetChildren()) do
if player.userId == receiptInfo.PlayerId then
-- check which product was purchased (required, otherwise you'll award the wrong items if you're using more than one developer product)
if(tonumber(receiptInfo.ProductId) == prodId)then
--Your function HERE
end
end
end
-- tell ROBLOX that we have successfully handled the transaction (required)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local marketplace = game:GetService("MarketplaceService")
marketplace.PromptProductPurchaseFinished:Connect(function(userId, productId, wasPurchased)
if wasPurchased then
print("Success!")
else
print("Fail!")
end
end)
Don’t use this to verify if a developer product was purchased but use this if you need an event which is fired whenever a developer purchase prompt is closed.