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

How do I give the player the stats that they buy?

local MarketplaceService = game:GetService("MarketplaceService")

local Products = {
	[335171701]=function(receipt,player) --100 Power
		player.leaderstats.Power.Value = player.leaderstats.Value + 100	
	end
}

function MarketplaceService.ProcessReceipt(receiptinfo)
	local playerProductKey = receiptinfo.PlayerId..":"..receiptinfo.PurchaseId
	local plr = game:GetService("Players"):GetPlayerByUserId(receiptinfo.PlayerId)
	
	local handler
	for ProductId, func in ipairs(Products) do
		if ProductId == receiptinfo.ProductId then
			handler = func break
		end
	end
	
local suc = pcall(handler,receiptinfo,plr)
return Enum.ProductPurchaseDecision.PurchaseGranted
end

and the output says, bad argument pcall, but i don't know what that means.

3 comments

0

Pcall should be wrapping a function, it can then stop the function and not the script if  need be.  “pcall(function()” 

0

I don't even see a need for a pcall here

1 answer

The way I see it, you really do not need to pcall the handler. You should be fine just using Products[receiptInfo.ProductId](receiptInfo, player)

That would work just fine as that was how you set up your dictionary (Products).

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