Hit detect script somehow broken

So I created a “hit detect” script inside of my enemy’s AI script. What it’s supposed to do is wait until the enemy has been attacked. The script works perfectly in Studio but when I play it “In-game”, I get this:

Attempt to index nil with Value (Line 29)

Here’s how the AI’s organized:

image

And here is the script:

EnemyCharacter:FindFirstChild("HumanoidRootPart").Touched:Connect(function(hit)
	if not canBeDamaged then
		return
	end
	if hit.Parent:FindFirstChild("Humanoid") then --Checks to see if the player is a humanoid
		
		local PlayerBodPts = { --All parts that the player uses to hit
			hit.Parent:FindFirstChild("Left Arm"),
			hit.Parent:FindFirstChild("Right Arm"),
			hit.Parent:FindFirstChild("Right Leg")
		}
		
		local HitConfig = hit.Parent:FindFirstChild("HitConfig")
		print("Okay dude... :/")
		
		for i,v in pairs(PlayerBodPts) do
			
			if hit.Parent:FindFirstChild("isAttacking").Value then --Line 29

Is this because of a bug or an error I made? Answers are welcome! :smiley:

1 Like

The error means that “isAttacking” does not exist under hit.Parent whenever line 29 is run.

if hit.Parent:FindFirstChild("isAttacking")

You should verify that this instance exists first but attempting to index its “Value” property.

1 Like

If the character exists, then you don’t have the value in the character or the value is getting deleted.