Does Anyone know how to make this where if the player is on the right, left or behind of the eye it wont follow them? so it should only follow them if there in sight which is straight ahead of the eyes.
local Eye = game.Workspace:WaitForChild("Eye")
local Players = game:GetService("Players")
local RS = game:GetService("RunService")
local MaxDistance = 40 --Diamater not radius (which means it's aprox 5 from it)
local FindPlayer = function()
local c = game.Workspace:GetChildren()
for i,v in ipairs(c) do
if Players:GetPlayerFromCharacter(v) then
local Head = v:FindFirstChild("Head")
if (Head.Position - Eye.Position).Magnitude < MaxDistance then
return Head
end
end
end
return false
end
RS.Heartbeat:Connect(function()
if FindPlayer() then
local Target = FindPlayer()
Eye.CFrame = CFrame.new(Eye.Position,Target.Position)
end
end)