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

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

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?

2 comments

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

0

It works now, thank you!

1 answer

✓ Accepted answer

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)

2 comments

0

stop FREAKING GIVING AWAY CODE YOU TROG EXPLAIN HOW ITW ORKS

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

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