Attemp to index nil with 'FindFirstChild'

Hello! Any reason why I could be possibly getting this error? I am very stuck, and very much confused. Any help will be appreciated!

Line:

		local petData = require(game.ReplicatedStorage.Game:FindFirstChild("Pets"):FindFirstChild(pet.Name):FindFirstChild(pet.Name))

image

1 Like

one of these :FindFirstChild()'s are returning nil, so try to print them all out individually

2 Likes

This error means that an object you’re trying to find a child of doesn’t exist.

If you’re doing this on the client, the things you’ve put in ReplicatedStorage (in this case, Game and its children) won’t be loaded immediately. You might want to replace FindFirstChild() with WaitForChild() so that the script can wait for the children to appear if they aren’t already there instead of just returning nil.

1 Like

Okay, I think I found the issue. Since the Model pet name is Pet, it’s trying to find the folder Pet. I am pretty sure that is the reason.

		print(pet.Name)
		print(game.ReplicatedStorage.Game:FindFirstChild("Pets"))
		print(game.ReplicatedStorage.Game:FindFirstChild("Pets"):FindFirstChild(pet.Name))
		print(game.ReplicatedStorage.Game:FindFirstChild("Pets"):FindFirstChild(pet.Name):FindFirstChild(pet.Name))

image

1 Like