Why is this thing running and making an error?

So basically I have a if statement and when the thing I’m checking for isnt there then it makes an error.
Code:

		if part.Parent:FindFirstChild('Humanoid') then -- this is where it is erroring
			print('This is a hum')
			local hum = part.Parent:FindFirstChild('Humanoid')
			hum:LoadAnimation(script:FindFirstChild('Backwards')):Play()
		end

The error I get is the standard

ServerScriptService.Attacks.EffectsModule:20: attempt to index nil with 'FindFirstChild'

I am not sure what the rest of your script looks like, but the error is saying that the part’s parent is nil.

part.Parent == nil -- That is what the error is telling you.

I suggest that you check the validity of the part’s parent and the validity of the part before continuing.

1 Like

I added

print(part.Name)
and now its not making errors.

I have no idea why
But thanks

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