Hi i am trying to make to npc detect a player in sight and once player is behind the wall the npc can't see him. Everything works fine expect raycast please help me.
local RunService = game:GetService("RunService") local npc = game.Workspace.NPC local Character = game.Players.LocalPlayer.Character RunService.RenderStepped:Connect(function() local npcToCharacter = (Character.Head.Position - npc.Head.Position).Unit local npclook = npc.Head.CFrame.LookVector local dotproduct = npcToCharacter:Dot(npclook) local detectRay = Ray.new(npc.Head.Position, (Character.Head.Position - npc.Head.Position).Unit * 5000) local hit , position = game.Workspace:FindPartOnRayWithIgnoreList(detectRay, (npc)) if hit == Character then if dotproduct > 0.5 then workspace.Baseplate.BrickColor = BrickColor.new("Medium red") else workspace.Baseplate.BrickColor = BrickColor.new("Medium green") end end end)