How Would I Add A Raycasting Function Where The Neighbor Will Only Chase A Player If He Sees One Infront Of Him And Can Exclude Any Transparent Objects, While Using Path Finding To Help Him Get To The Player, But He Stops Chasing After 7 Seconds? Here is the script I have:
local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 170
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("HumanoidRootPart")
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 true do
wait(math.random(1,2))
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position)
if script.Parent.Randomizer.Value == 1 then
if script.Parent.UpperTorso.Sound.IsPlaying == false then
script.Parent.UpperTorso.Sound:Play()
else
end
else
if script.Parent.UpperTorso.Sound2.IsPlaying == false then
script.Parent.UpperTorso.Sound2:Play()
else
end
end
else
script.Parent.UpperTorso.Sound:Stop()
script.Parent.UpperTorso.Sound2:Stop()
end
end

2 comments
With lookvector.
can you give a detailed explanation instead of just saying "With Lookvector"