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

Getting an error when trying to prompt the player w/ a purchase?

Asked by 4 years ago
Edited 4 years ago

Code I have so far:

local button = script.Parent
local ProductID = 607020275
local Player = game.Players.LocalPlayer

button.MouseButton1Click:Connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(Player.UserId, ProductID)
end)

I am not too sure why I am getting the error: Players.BloxburgAccountBart.PlayerGui.ProductsGUI.MainFrame.XDmodeButton.Script:6: attempt to index upvalue 'Player' (a nil value).

Why is it a nil value?

Idk if this other stuff may help but I'll give it anyways:

local MarketplaceService = game:GetService("MarketplaceService")
local ProductID = 607020275

MarketplaceService.ProcessReceipt = function(receiptinfo)
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptinfo.PlayerId then
            if receiptinfo.ProductId == ProductID then
                game:FindFirstChildWhichIsA("Humanoid")
                if ( Humanoid ) then
                    Humanoid.JumpPower = 100                    
                end
            end
        end
    end
end

Could someone please address the script's issue?

0
is the first script a localscript? If not, make it one. Also, for PromptProductPurchase, it need the player instance, not the player's userid theking48989987 2147 — 4y
0
It works now, thank you! sean_thecoolman 189 — 4y

1 answer

Log in to vote
2
Answered by
sheepposu 561 Moderation Voter
4 years ago

For purchasing, this should work

Purchase script in ServerScriptService

local mps = game:GetService('MarketplaceService')
local credits = --purchase id

mps.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == credits then
        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        player.Coins.Value = player.Coins.Value + 50
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

Button Script

local mps = game:GetService('MarketplaceService')
local id = --purchase id

script.Parent.MouseButton1Click:Connect(function()
    mps:PromptProductPurchase(game.Players.LocalPlayer, id)
end)
0
stop FREAKING GIVING AWAY CODE YOU TROG EXPLAIN HOW ITW ORKS Fifkee 2017 — 4y
0
The LocalScript prompts the purchase with a built-in event and the Purchase catches the event. Next it checks the id of the receipt and finds the player by their UserId which is in the receipt and gives them the money. Finally is grants the purchase sheepposu 561 — 4y
Ad

Answer this question