Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is :PromptProductPurchase not working?

Asked by
Komas19 34
1 year ago
Edited 1 year ago

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

Log in to vote
0
Answered by 1 year ago

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.

0
thx Komas19 34 — 1y
Ad

Answer this question