-
What do you want to achieve?
I want to be able to reward users for their purchases. -
What is the issue?
The function “MarketplaceService.PromptPurchaseFinished:Connect(function(Buyer, productID, isPurchased)” is not executing after a purchase. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have rewritten it several times and will not work. I had gotten the fuction from the developer wiki and tried multipule times.
local MarketplaceService = game:GetService("MarketplaceService")
local HttpServ = game:GetService("HttpService")
local WebUrl = "private"
local Events = game:GetService("ReplicatedStorage")
function PromptBuyer()
print("Prompting!")
MarketplaceService:PromptProductPurchase(Buyer,productID)
print(Buyer, productID, isPurchased)
end
MarketplaceService.PromptPurchaseFinished:Connect(function(Buyer, productID, isPurchased)
if isPurchased then
print("Purchased!")
Buyer.PlayerData.Diamonds.Value = Buyer.PlayerData.Diamonds.Value + PurchaseAmount
local data =
{
content = "**[Buyer:]** "..Buyer.." **[Diamonds Bought:]** "..PurchaseAmount;
username = "PurchaseLog";
}
HttpServ:PostAsync(WebUrl, HttpServ:JSONEncode(data))
else
print("Exited")
end
end)
Events.Purchases.OnServerEvent:Connect(function(Player,Serial)
Buyer = Player
if Serial == "p5" and Buyer.MembershipType == Enum.MembershipType.Premium then
productID = 963023584
PurchaseAmount = 5
PromptBuyer()
elseif Serial == "p10" and Buyer.MembershipType == Enum.MembershipType.Premium then
productID = 963023472
PurchaseAmount = 10
PromptBuyer()
elseif Serial == "p25" and Buyer.MembershipType == Enum.MembershipType.Premium then
productID = 963023436
PurchaseAmount = 25
PromptBuyer()
elseif Serial == "p50" and Buyer.MembershipType == Enum.MembershipType.Premium then
productID = 963023610
PurchaseAmount = 50
PromptBuyer()
elseif Serial == "p100" and Buyer.MembershipType == Enum.MembershipType.Premium then
productID = 963023661
PurchaseAmount = 100
PromptBuyer()
elseif Serial == "p200" and Buyer.MembershipType == Enum.MembershipType.Premium then
productID = 963023698
PurchaseAmount = 200
PromptBuyer()
PurchaseAmount = 1
elseif Serial == "5" then
productID = 1
PurchaseAmount = 1
PromptBuyer()
elseif Serial == "10" then
productID = 1
PurchaseAmount = 1
PromptBuyer()
elseif Serial == "25" then
productID = 1
PurchaseAmount = 1
PromptBuyer()
elseif Serial == "50" then
productID = 1
PurchaseAmount = 1
PromptBuyer()
elseif Serial == "100" then
productID = 1
PurchaseAmount = 1
PromptBuyer()
elseif Serial == "200" then
productID = 1
PurchaseAmount = 1
PromptBuyer()
else
print("Invalid Product!")
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.