IV BEEN WORKING ON THIS FOR YEARS. I STILL CANT FIND THE ANSWER. Kinds like the game on Roblox "Notoriety", where guards see you, and when they do it raises detection. I want that, but I'm so frustrated i can't find the answer. the other day finally I was given a clue. two clues actually.
One person said exactly this:
you can use camera.GetPartsObscuringTarget()
more here
someone else said exactly this:
You can raycast from the NPC's head to the target, if it hits a body part belonging to them, then the NPC sees them.
view source
1 local maximumDistance = 300 -- the ray's max distance, in studs
2 local ray = Ray.new(NPC.Head.Position, (TARGET.HumanoidRootPart.Position - NPC.Head.Position).Unit * maximumDistance)
3 local hit = workspace:FindPartOnRayWithIgnoreList(ray,{NPC})
4
5 if hit.Parent == target.Parent then
6 print("i can see the player")
7 else
8 print("i cannot see the player")
9 end
Keep in mind that I haven't tested the code above, so it may need some tweaking.
So I paid attention and spent some days trying to figure out how to use it. i looked it up in about 1000 different ways and looked everywhere on the internet, couldnt find my answer. then i spent hours and even more days trying to figure it out myself. trying things. i stilll havent figured it out. please help me, im DYING to know for a game im working on! thanks

2 comments
you have NO idea how overwhelmed and frusterated i am.
This will be a bit hacky but https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToViewportPoint might be able to help