I am making a script that will make it so if this NPC sees me it will run the function Pursue. Search() is on a loop, so it runs over and over again. Read the note blocks.
function Search() for i = 1, #subjects do if subjects[i]:IsA("Player") then print("FoundPlayer") subjectChar = (subjects[i].Character) local subjectHead = subjectChar:findFirstChild("Head") local vec = subjectHead.Position - viewerHead.Position local isInFOV = (vec:Dot(subjectHead.CFrame.lookVector) > 0) print("Checkpoint")--This prints if (isInFOV) and (vec.magnitude < maxSightRange) then print("IsInFOV")--This does NOT print, he can clearly see me. local ray = Ray.new(viewerHead.Position,vec.unit*1000) local por = fpor(workspace,ray,subjectChar,false) if por:IsDescendantOf(subjectChar) then Pursue() end end end end end