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

Why is this dev product script not prompting purchase? [ANSWERED]

Asked by 9 years ago

Hi guys! This local script is in a surfacegui on a part that is in the Workspace. Any ideas why this is not prompting purchase? :) Thanks! jj

local buyButton = script.Parent
local productId = 25210034
local mps = game:GetService("MarketplaceService")

function getPlayerById(id)
for i,v in pairs(game.Players:GetPlayers()) do
if v.userId == id then
return v
end
end
end

buyButton.MouseButton1Click:connect(function()
mps:PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

mps.ProcessReceipt = function(info)
local plr = getPlayerById(info.PlayerId)
if plr and plr:FindFirstChild("leaderstats") and plr.leaderstats:FindFirstChild("Coins") then
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 10000
end
end
0
Is the surfacegui inside of the player's PlayerGui, or inside of the brick? In order for game.Players.LocalPlayer to function properly, the LocalScript must be inside of the player. ChipioIndustries 454 — 9y
0
Ah! It is in the surfacegui which is in the brick. But If I put it in the player, then it will not be able to interact with the brick as it will not be parented to it and it will not be able to access it from a local script?! jjwood1600 215 — 9y
0
The SurfaceGui does not need to be inside of the PlayerGui for the player to interact with it. Connect to the buttons locally in a LocalScript. Access the gui as it is. Also, do not set ProcessReceipt locally, and it needs to return Enum.ProductPurchaseDecision.PurchaseGranted or the transaction will not go through. 1waffle1 2908 — 9y
1
Put the SurfaceGui in StarterGui and reference the 'buyButton' from workspace. Then, set the adornee of the SurfaceGui to that buutton. Goulstem 8144 — 9y

Answer this question