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

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

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

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

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