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

line 13: attempt to index number with 'PlayerId'? [i need to keep writing to get attention xD ]

#Problem

Okay, so for my game I've made a bank where you can buy devproducts, and each transaction you get some coins.

BUT, i got this error;

Players.maxpax2009.PlayerGui.BankGui.Prompters.ProductPromptHandler:13: attempt to index number with 'PlayerId'

It's on line 13

Why tho, it should work completely fine!

#Code

local MarketPlaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local Ids = {
	["Transaction1"] = {id = 1230432, price = 200},
	["Transaction2"] = {id = 12012, price = 500},
	["Transaction3"] = {id = 12313, price = 2000},
	["Transaction4"] = {id = 123323, price = 5000}
	
}

local function ProcessReceipt(receiptInfo, price)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not player then
		-- if the player probably left the game
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if player then
		-- what you want the devproduct to do
	   player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + price
		
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

for i, v in pairs(Ids) do
	for _, x in pairs(script.Parent.Parent.ShopFrame:GetChildren()) do
		local found = false
		
		if x.Name == i then
			found = true
			
			x.ImageButton.Activated:Connect(function()
				MarketPlaceService:PromptProductPurchase(Players.LocalPlayer, v.id)
				
				MarketPlaceService.ProcessReceipt = ProcessReceipt(v.price)
			end)	
		end
	end
end

1 comment

0

Are you secretly maxpax2009

1 answer

✓ Accepted answer

On line 37, you're doing MarketPlaceService.ProcessReceipt = ProcessReceipt(v.price).

So first, you're setting the callback to a product purchase decision(that's what it returns), and second, you're passing the price as the first parameter, but it thinks that it's the receiptInfo.

Fix:

MarketPlaceService.ProcessReceipt = ProcessReceipt

Now it actually gives the function itself instead of what it returns.

Hope this helped

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