Hi I have a script from developerProuct.Recipt and it worked fine until I add one thing to find the player name in a string when i play the output tells me that attempt to index nil with ‘Name’ does anyone know how to fix this?
here is the script:
local Player = game.Players.LocalPlayer
local skip1 = 968774699
local skip2 = 973288118
local CottonSmall = 987831302
local function processReceipt(receiptInfo, Player)
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local Info = game.Workspace.WingsSettings:FindFirstChild(Player.Name)
local Size = Info:FindFirstChild("CottonSelectionSize")
local Color = Info:FindFirstChild("CottonSelectionColor")
if receiptInfo.ProductId == skip1 then
print("working...")
elseif receiptInfo.ProductId == skip2 then
print("working")
elseif receiptInfo.ProductId == CottonSmall then
if Size.Value == "Small" and Color.Value == "Pink" then
print("...")
elseif Size.Value == "Small" and Color.Value == "Blue" then
print("...")
elseif Size.Value == "Small" and Color.Value == "Green" then
print("...")
elseif Size.Value == "Small" and Color.Value == "Purple" then
print("...")
elseif Size.Value == "Small" and Color.Value == "MultiColor" then
print("...")
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
Extra:
Well maybe you wonder why I look for the name of the player in a string that is because I saved the information in the string with the name of the player and it is easier for me to access the information
looks like im blind, thanks for the correction, but is the Player value even set, as in if you do print(Player) does it give some uservalue or just nil? did you not mean to check the name of the player you get from the receipt?
First, processReciept is an important callback function and it should be done server side, idk why you’re referencing a local player.
Second ProcessRecipt only passes in one argument so local function processReceipt(receiptInfo, Player)
Player is still nill, because nothings passed in. And this is where you’re getting the error. You should use the player variable you made here local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
A number of things are wrong here, so i’m just going to point all of them out:
If you’re using a local script, don’t - ProcessReceipt should be handled in a normal script. Also, normal scripts wouldn’t have a specified LocalPlayer, which only local scripts have
ProcessReceipt only returns the receiptInfo as a parameter, so it wouldn’t return Player as a parameter. The player is obtainable using the receiptInfo table, which you’ve even done in the script. This is the cause of the error on this line: local Info = game.Workspace.WingsSettings:FindFirstChild(Player.Name) because Player is nil, and the error tells you that you’re trying to index nil with ‘Name’