AI giving error

Hello, I’m making an AI for zombies but giving an error
Screenshot_5
This output code I added a value in players and zombies (“Zombie” named)
for checking zombie or human in this code I don’t want zombies trying to find zombies
but the code giving me an error

function findTarget()
	local dist = 50
	local target = nil
	local potentialTargets = {}
	local seeTargets = {}
	for i,v in ipairs(workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso") or v:FindFirstChild("HumanoidRootPart")
		local ZombC = v:FindFirstChild("Zombie").Value
		if human and torso and v.Name ~= script.Parent.Name then
			if (myRoot.Position - torso.Position).magnitude < dist and human.Health > 0 and ZombC == false then
				table.insert(potentialTargets,torso)
			end
		end
	end

This code part

Try changing these lines

		local ZombC = v:FindFirstChild("Zombie").Value
		if human and torso and v.Name ~= script.Parent.Name then
			if (myRoot.Position - torso.Position).magnitude < dist and human.Health > 0 and ZombC == false then
				table.insert(potentialTargets,torso)
			end
		end

to this

		local ZombC = v:FindFirstChild("Zombie")
		if not ZombC:FindFirstChild("Value") then
			continue
		end
		if human and torso and v.Name ~= script.Parent.Name then
			if (myRoot.Position - torso.Position).magnitude < dist and human.Health > 0 and not ZombC.Value then
				table.insert(potentialTargets,torso)
			end
		end


Thanks but giving still error
Screenshot_7

unction findTarget()
	local dist = 50
	local target = nil
	local potentialTargets = {}
	local seeTargets = {}
	for i,v in ipairs(workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local torso = v:FindFirstChild("Torso") or v:FindFirstChild("HumanoidRootPart")
		local ZombC = v:FindFirstChild("Zombie")
		if not ZombC:FindFirstChild("Value") then
			continue
		end
		if human and torso and v.Name ~= script.Parent.Name then
			if (myRoot.Position - torso.Position).magnitude < dist and human.Health > 0 and not ZombC.Value then
				table.insert(potentialTargets,torso)
			end
		end

Then change this

if not ZombC:FindFirstChild("Value") then

to this and it should work

if ZombC and not ZombC:FindFirstChild("Value") then

1 Like

I am so sorry but not worked
Screenshot_8

Hey “ZombC” is a value
Screenshot_9
like this

Oh I edited some scripts and worked thanks