Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is :PromptProductPurchase not working?

So, for a weird reason, :PromptProductPurchase isn't working, nothing appear on the output, the prompt doesn't show up. (also the product exists lol)

Code :

local id = 1281319566
local market = game:GetService("MarketplaceService")
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local info = market:GetProductInfo(id, Enum.InfoType.Product)

while true do
	wait(1)
	script.Parent.Text = "Buy ! (R$ : "..info.PriceInRobux.." )"
end

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

Same issue for :PromptGamepassPurchase :

local id = 54938026
local market = game:GetService("MarketplaceService")
local user = game:GetService("Players").LocalPlayer
local info = market:GetProductInfo(id, Enum.InfoType.GamePass)

while true do
	wait(1)
	script.Parent.Text = "Buy ! (R$ : "..info.PriceInRobux.." )"
end

script.Parent.MouseButton1Click:Connect(function()
	market:PromptGamePassPurchase(user, id)
end)

Both of them are in a LocalScript

1 answer

✓ Accepted answer

A while loop, as you may already know, executes each line of code one after another. In its entirety, code is read from top to bottom, so the while loop is executed first. Since it's a while loop, the reader will continue returning to line 6 after it's finished running the last line of code nested in the loop. Due to that fact, the program can never subscribe to the MouseButton1Click event.

Moving the event above the while loop should do the trick:

local id = 1281319566
local market = game:GetService("MarketplaceService")
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local info = market:GetProductInfo(id, Enum.InfoType.Product)

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

while true do
	wait(1)
	script.Parent.Text = "Buy ! (R$ : "..info.PriceInRobux.." )"
end

I'm a little stumped as to why this was needed in a while loop:

script.Parent.Text = "Buy ! (R$ : "..info.PriceInRobux.." )"

Moving it out of the loop might also fix the problem, but I'm not quite sure about it.

1 comment

0

thx

This discussion is preserved as it was. New answers, comments, and votes are closed.