Getting error for no reason

I am getting the error . Script:100: attempt to index nil with 'FindFirstChild' . and I really don’t know why it’s happening.

Can someone help?

Script
	if HitPart.parent:FindFirstChild("Humanoid") then

		local holeDecal = a.Decal
		local red1 = Color3.fromRGB(83, 0, 0)
		local red2 = Color3.fromRGB(34, 0, 0)

		a.Name = "BodyBulletHole"
		holeDecal.Color3 = Color3.fromRGB(136, 0, 0)

		local f = Instance.new("ParticleEmitter")
		f.Texture = "rbxassetid://241779220"

		f.Color = ColorSequence.new{
			ColorSequenceKeypoint.new(0, red1),
			ColorSequenceKeypoint.new(1, red2)
		}


		f.Size = NumberSequence.new{
			NumberSequenceKeypoint.new(0, 0),
			NumberSequenceKeypoint.new(1, 0.95)	
		}

		f.Transparency = NumberSequence.new{
			NumberSequenceKeypoint.new(0, 1),
			NumberSequenceKeypoint.new(0.1, 0.5),
			NumberSequenceKeypoint.new(0.4, 0.75),
			NumberSequenceKeypoint.new(1, 1)
		}


		f.LightEmission = 0.2
		f.LightInfluence = 1
		f.Lifetime = NumberRange.new(0.15, 0.35)
		f.Rate = 200
		f.Rotation = NumberRange.new(-360, 360)
		f.RotSpeed = NumberRange.new(-40, 270)
		f.Speed = NumberRange.new(2.5, 5)
		f.SpreadAngle = Vector2.new(15, 15)
		f.Shape = "Box"
		f.ShapeInOut = "Outward"
		f.ShapeStyle = "Volume"
		f.Acceleration = Vector3.new(0, -50, 0)
		f.Drag = 0
		f.TimeScale = 1
		f.Parent = a

		wait(7.5)

		f:Destroy()

	end

	if HitPart.parent:FindFirstChild("RagdollHumanoid") then

		local holeDecal = a.Decal
		local red1 = Color3.fromRGB(83, 0, 0)
		local red2 = Color3.fromRGB(34, 0, 0)

		a.Name = "BodyBulletHole"
		holeDecal.Color3 = Color3.fromRGB(136, 0, 0)

	end
end)

The script you provided doesn’t have a hundred lines and you didn’t highlight where the error is, but the error means that you’re doing somethingNil: FindFirstChild (whatever)

I am getting an error on the if HitPart.parent:FindFirstChild("RagdollHumanoid") then line but I don’t see anything wrong with the script.

Also, the full script is like 1000 lines so I don’t really want to paste that much.

I’m a noob scripter, but I believe it has something to do with your first line. I assume you are using a touched event and thus when the part is touching the floor, it tries to find a humanoid in the floor but doesn’t find any since the floor isn’t a character. It could also be because parent starts with a common “p”. Try doing this:

local door = script.Parent

door.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	if humanoid then
		--Your code
	end
end)
1 Like

In my opinion, there could be two reasons for this:

  • The variable is defined incorrectly
    or
  • The part does not exist anymore (yes, that’s possible! If that happens, you need to implement a condition that checks if the part’s parent is still there).

This seemed to work. Thank you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.