Index Nil `name`1

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to get passed this script error that has been blocking my progress
  2. What is the issue? Include screenshots / videos if possible!
    image

I haven’t looked for many solutions

Pet folder
image
Local Script Location
image
Main script and pet location
image

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new('Folder', player)
	leaderstats.Name = 'leaderstats'

	local Pet = Instance.new('Folder', player)
	Pet.Name = 'Pet'

	local coins = Instance.new("IntValue", leaderstats)
	coins.Name = 'Coins'
	coins.Value = 0

	player.CharacterAdded:connect(function(char)
		local attachment = Instance.new("Attachment", char.HumanoidRootPart)
		attachment.Name = "CharacterAt"

	end)
end)





game.ReplicatedStorage.Remotes.Add.OnServerEvent:Connect(function(player)
	local currency = 'Coins'
	local ammount = 1

	player.leaderstats[currency].Value = player.leaderstats[currency].Value +  ammount


end)  

game.ReplicatedStorage.RemoteFunctions.EquipPet.OnServerInvoke = function(player, pet)


	local currency = "Coins"
	local MainPet = game.ServerStorage.Pets:FindFirstChild(pet)

	if not player.Pet:FindFirstChild(MainPet.Name) then
		if player.leaderstats[currency].Value >= MainPet.Price.Value then
			player.leaderstats[currency].Value = player.leaderstats[currency].Value - MainPet.Price.Value
			local clonedPet = MainPet:Clone()
			local atPet = Instance.new("Attachment", clonedPet.PrimaryPart)

			local ap = Instance.new	("AlignPosition")
			ap.Parent = pet 
			ap.RigdigityEnabled = true 
			clonedPet.Parent = player.Character
			clonedPet:SetPrimaryPartCFrame(player.Character.Head.Cframe)
			ap.Attachment0 = atPet
			ap.Attachment1 = player.Character.HumanoidRootPart.CharacterAt
	
	




			return "Bought"
		else
			return "Not enough coins"
		end
	else
		return "Equip"
	end
end

This is the local script it connects to

script.Parent.MouseButton1Click:Connect(function()
	local result = game.ReplicatedStorage.RemoteFunctions.EquipPet:InvokeServer(script.Parent.Parent.Name)
end)

Also! i forgot to mention the script stops at Line 38

Okay, so the script is erroring because it doesn’t know what you are trying to find the Name of. It is erroring at

if not player.Pet:FindFirstChild(MainPet.Name) then

So, you’ll have to go through, and see what this is referencing. When testing the game, open up the player, and see if it exists. Likely, you mispelled something, or the like. That is the best I can debug without actually being able to test, but I hope this helps!

1 Like

Since the variable MainPet is a pet with the name passed as a parameter “pet,” can’t you just pass pet in the function instead of MainPet.Name?

Change this:

if not player.Pet:FindFirstChild(MainPet.Name) then

to this:

if not player.Pet:FindFirstChild(pet) then

Hi! so i’ve done this and it worked but once it worked it now says
attempt to index nil with ‘Price’

I’ll edit it and show u the explorer

Hi! so i’ve edited the location of all the assets on the post! hopefully this helps you!

Whenever you reference MainPet.Price, just change it to MainPet:FindFirstChild(“Price”)