Hello, I’m making an AI for zombies but giving an error
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
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
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