Attempt to index nil with 'Parent' without a nil

CustomiseHolder.Accessories.ChildAdded:Connect(function(accessory)
	wait()
	
	local Attach0 = accessory.Handle:FindFirstChildWhichIsA('Attachment')
	print(accessory)
	print(Dummy)
	print(Attach0)
	local Attach1 = Dummy:FindFirstChild(Attach0.Name, true)
	
	local Weld = Instance.new('Weld')
	Weld.Parent = accessory.Handle
	Weld.Part0 = Attach0.Parent
	print(Weld)
	Weld.Part1 = Attach1.Parent -- ERROR HERE
	Weld.C0 = Attach0.CFrame
	Weld.C1 = Attach1.CFrame

	accessory.Parent = Dummy
end)

attempt to index nil with ‘Parent’
Not sure what exactly the ‘nil’ is

Prints

Hat - 162066057

Dummy

HatAttachment

Weld

1 Like
CustomiseHolder.Accessories.ChildAdded:Connect(function(accessory)
	wait()
	
	local Attach0 = accessory.Handle:FindFirstChildWhichIsA('Attachment')
	print(accessory)
	print(Dummy)
	print(Attach0)
	local Attach1 = Dummy:FindFirstChild(Attach0.Name, true) --Does this result as nil?
	print(Attach1) --Print to check if this is nil

	local Weld = Instance.new('Weld')
	Weld.Parent = accessory.Handle
	Weld.Part0 = Attach0.Parent
	print(Weld)
	Weld.Part1 = Attach1.Parent -- ERROR HERE
	Weld.C0 = Attach0.CFrame
	Weld.C1 = Attach1.CFrame

	accessory.Parent = Dummy
end)

It looks like Attach1 might not find anything in the Dummy. Print(Attach1) to see if it results as nil.

1 Like

Please correct me if I’m wrong, but when I read your code I saw that you’re setting the weld’s Part1 to the Parent of Attach1, which is “Dummy”. I’m not sure if this was intentional or not, so just making sure :slight_smile:

local Attach1 = Dummy:FindFirstChild(Attach0.Name, true)

The second parameter on FindFirstChild, when set to true, makes it search recursively through all descendants. It could be right underneath the dummy like you said, but it could be much deeper. In this case it’s likely that it found something like this:

...Dummy.Accesorry.Handle.Attachment
1 Like