When more than 1 zombie name to ignore, the zombies attack themselves

I want to make the Zombie script ignore 2 models instead of one by its name, but after doing that, one zombie doesn’t chase anything. And the other one chases themselves or the other zombie type.

Here is the part of the script, i’m using the drooling zombie ai script

local function handleHit(other)
if canHit then
	if other and other.Parent and other.Parent.Name ~= "BnW" and "Cone" and other.Parent:FindFirstChild("Humanoid") then
		local enemy = other.Parent						
		if enemy.Humanoid.WalkSpeed > 0 then
			enemy.Humanoid.Health = enemy.Humanoid.Health - configs["Damage"]
			canHit = false
		end
	end
else

what the zombies need is more brainpower
too stupid and needs skoo
anyways, can you explain the code better? what is “other”?

Hey, you forget to add another Parent.Name check on the 2nd string check.

local function handleHit(other)
if canHit then
	if other and other.Parent and other.Parent.Name ~= "BnW" and other.Parent.Name ~= "Cone" and other.Parent:FindFirstChild("Humanoid") then
		local enemy = other.Parent						
		if enemy.Humanoid.WalkSpeed > 0 then
			enemy.Humanoid.Health = enemy.Humanoid.Health - configs["Damage"]
			canHit = false
		end
	end
else
2 Likes

alternatively to @Arexael’s fix

local ignore_list = {"BnW", "Cone"}
local function handleHit(other)
if canHit then
	if other and other.Parent and other.Parent:FindFirstChild("Humanoid") and not ignore_list[other.Parent.Name] then
		local enemy = other.Parent						
		if enemy.Humanoid.WalkSpeed > 0 then
			enemy.Humanoid.Health = enemy.Humanoid.Health - configs["Damage"]
			canHit = false
		end
	end
else

(fixed up now and should work)

1 Like

You actually forgot an and in between ...other.Parent (and here) other.Parent:FindFirstChild...

1 Like

thank you! didn’t spot that until now.

1 Like

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