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 5 years ago
Edited 5 years ago

Code I have so far:

1local button = script.Parent
2local ProductID = 607020275
3local Player = game.Players.LocalPlayer
4 
5button.MouseButton1Click:Connect(function()
6    game:GetService("MarketplaceService"):PromptProductPurchase(Player.UserId, ProductID)
7end)

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:

01local MarketplaceService = game:GetService("MarketplaceService")
02local ProductID = 607020275
03 
04MarketplaceService.ProcessReceipt = function(receiptinfo)
05    for i, player in ipairs(game.Players:GetChildren()) do
06        if player.userId == receiptinfo.PlayerId then
07            if receiptinfo.ProductId == ProductID then
08                game:FindFirstChildWhichIsA("Humanoid")
09                if ( Humanoid ) then
10                    Humanoid.JumpPower = 100                   
11                end
12            end
13        end
14    end
15end

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 — 5y
0
It works now, thank you! sean_thecoolman 189 — 5y

1 answer

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

For purchasing, this should work

Purchase script in ServerScriptService

01local mps = game:GetService('MarketplaceService')
02local credits = --purchase id
03 
04mps.ProcessReceipt = function(receiptInfo)
05    if receiptInfo.ProductId == credits then
06        local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
07        player.Coins.Value = player.Coins.Value + 50
08    end
09    return Enum.ProductPurchaseDecision.PurchaseGranted
10end

Button Script

1local mps = game:GetService('MarketplaceService')
2local id = --purchase id
3 
4script.Parent.MouseButton1Click:Connect(function()
5    mps:PromptProductPurchase(game.Players.LocalPlayer, id)
6end)
0
stop FREAKING GIVING AWAY CODE YOU TROG EXPLAIN HOW ITW ORKS Fifkee 2017 — 5y
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 — 5y
Ad

Answer this question