Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to tell if a player's head (or torso) is facing towards an NPC?

I'm working on a model of SCP-096 and I need help knowing if the head (or in this case, torso) is facing towards the face of the SCP. The normal script uses the variables TargetTorso: the torso of the player it detects is near it (needs to be who looks at it) NoticeDistance: I think this might just be able to be taken away. Chasing: self-explanatory, goes into raging stage. and a bunch of other "targets". The old script goes as follows.

local NoticeDistance=8; local TargetTorso; for _,TargetModel in pairs(game:GetService("Workspace"):GetChildren())do if TargetModel.className=="Model"and TargetModel~=SCP096 and TargetModel.Name~=SCP096.Name and TargetModel:FindFirstChild("HumanoidRootPart")and TargetModel:FindFirstChild("Head")then local TargetPart=TargetModel:FindFirstChild("HumanoidRootPart"); local FoundHumanoid; for _,Child in pairs(TargetModel:GetChildren())do if Child and Child.ClassName=="Humanoid"and Child.Health~=0 then FoundHumanoid=Child; end; end; if TargetPart and FoundHumanoid and FoundHumanoid.Health~=0 and(TargetPart.Position-SCP096HumanoidRootPart.Position).magnitude<NoticeDistance then TargetTorso=TargetPart; NoticeDistance=(TargetPart.Position-SCP096HumanoidRootPart.Position).magnitude; AttackDebounce=true; spawn(function() Chasing=true;

--then the SCP starts raging and then chasing the TargetTorso until it kills it. I need help scripting a way to find if they are looking at his face (possible using LookVector, or LookVector:Dot), while having it work with the script itself.

2 answers

You could either use raycasting; or you could use a long straight weightless invisible part that would be part of the players default StarterCharacter model, have a script in it that sets a serverstorage boolvalue to true/false & then use an on Value.Changed system in the rest of your script.

This discussion is preserved as it was. New answers, comments, and votes are closed.