-
What do you want to achieve? I’m trying to make a ProcessReceipt function, for my Shop GUI, to handle purchases in a better way.
-
What is the issue? As stated in the title, I’m getting an “Attempt to index nil with ‘PlayerId’” error.
-
What solutions have you tried so far? I’ve looked on Roblox Developer Docs, but it didn’t help me.
This is the script:
local marketplaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local LittleBagId = 1358219495
local SmallBoxId = 1358219815
local LargeBoxId = 1358220015
local BarrelId = 1358220122
local function processReceipt(receiptInfo)
local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
local leaderstats = player:WaitForChild("leaderstats")
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId == SmallBoxId then
if player then
local Gems = leaderstats["💎Gems"]
Gems.Value += 4500
end
elseif receiptInfo.ProductId == LittleBagId then
if player then
local Gems = leaderstats["💎Gems"]
Gems.Value += 3000
end
elseif receiptInfo.ProductId == LargeBoxId then
if player then
local Gems = leaderstats["💎Gems"]
Gems.Value += 8000
end
elseif receiptInfo.ProductId == BarrelId then
if player then
local Gems = leaderstats["💎Gems"]
Gems.Value += 10000
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
marketplaceService.ProcessReceipt = processReceipt()