I have a table that contains a bunch of Product Ids. When a player clicks a button. They get prompted with a purchase. Then, After they choose Ok>Ok, or Cancel, They get prompted with the next Product Id in the table. To do this, I am using a deprecated Event, but it just doesn’t matter.
The player gets prompted with the first product. Then, after they make their decision, the next prompt is an error that reads “Your purchase failed because something went wrong. Your account has not been charged. Please try again later.”
So, These are the important parts of my script.
–Local Script
local function promptPurchase()
if table.getn(AllItems)>0 then
local player = Players.LocalPlayer
local Variable = 0
for i,v in pairs(AllItems) do
MarketplaceService:PromptProductPurchase(player, v)
ReplicatedStorage.ProductsPurchasingEvent.OnClientEvent:Connect(function()
Variable = 1
end)
repeat wait() until Variable == 1
Variable = 0
wait(2)
end
end
end
script.Parent["Butttons/Data"].ImageButton.MouseButton1Click:Connect(promptPurchase)
–ServerScript in ServerScriptService and the RemoteEvent is in Replicated Storage
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local function processReceipt(receiptInfo)
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.PromptProductPurchaseFinished:Connect(function (player, assetid, OkCancel)
local players = game:GetService("Players"):GetPlayerByUserId(player)
ReplicatedStorage.ProductsPurchasingEvent:FireClient(players)
return
end)
MarketplaceService.ProcessReceipt = processReceipt
How can I make it to where the player doesn’t have to click a different button for each product? Is it something ROBLOX has in place, or am I doing it wrong? Please help.