Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I create Raycast and use it to detect a player near by?

Asked by 6 years ago

Details I want to know how to use Ray cast and implement that to detect if the npc is infront of the Player. I do not want it to detect players through walls , only in the range of the NPC.

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

this is very simple use find part on ray

in script

local npc = script.Parent

while wait(1) do
local ray= Ray.new(npc.HumanoidRootPart.Position, npc.HumanoidRootPart.CFrame.lookVector)

if FindPartOnRay(ray).Parent.Humanoid then 
-- ur code  
end 

end
Ad

Answer this question