Attempt to index nil with 'Name'

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
:slight_smile:

Yes that line :frowning: :frowning:

You haven’t specified which line is giving the error!

sorry is line 17 :confused: :confused:

The function does have player in the function.

Why are you setting player to player?

sorry my error that was not in the script, the script does not have player = player

I’m sorry that was not planned to be there

uppercase Player does not exist, its lowercase when you set it

It actually did/does exist? Its the second parameter at the processReceipt function.

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?

1 Like

So i youst did the print(Player) and gives me nil and yes i want to check the name of the player

it will probably work if you change the uppercase Player to just player
edit: on line 17 that is, not in the parameters

Theres a good bit wrong with this script

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)

3 Likes

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’

6 Likes

So how can i find the player name on the string?

I assume you mean what this line does local Info = game.Workspace.WingsSettings:FindFirstChild(Player.Name)?

Just use the player variable you’ve already predefined:

local Info = game.Workspace.WingsSettings:FindFirstChild(player.Name)
2 Likes

OMG thanks so mouch!
:slight_smile: :grinning: :grinning: :grinning: :grinning: :grinning: