Hi guys. This walk script for a Zombie keeps returning the following error right after it's death. It annoys me because nothing is wrong with the code.
20:18:30.178 - Workspace.Lightning Zombie.walk:33: attempt to index a nil value 20:18:30.181 - Stack Begin 20:18:30.182 - Script 'Workspace.Lightning Zombie.walk', Line 33 20:18:30.183 - Stack End
local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
local torso = script.Parent:FindFirstChild("Torso")
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = false
local dist = 1000
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("Right Arm")
human = temp2:findFirstChild("Humanoid")
Zombie = temp2:FindFirstChild("Zombie")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and Zombie == nil then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while torso ~= nil do
wait()
local target = findNearestTorso(script.Parent:FindFirstChild("Torso").Position) --Problem Here
if target ~= false and target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end

2 comments
That happened to me with my AI. I just ignore it.
"Give up" is not a useful answer.