Monsters are targets when there is a wall in between?
function findNearestTorso(pos)
local list = workspace:FindFirstChild("PlrHolder"):children()
local torso = nil
local dist = script.Parent.Config.MonsterDistance.Value
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) and game.Players:GetPlayerFromCharacter(temp2)~=nil then
temp = temp2:findFirstChild("Right Arm")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while wait(0.1) do
local target = findNearestTorso(script.Parent:FindFirstChild("Torso").Position)
if target ~= nil then
script.Parent:FindFirstChild("Enemy"):MoveTo(target.Position, target)
end
end