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

How to make a raycast ignore more things?

Is their a way to make raycast to ignore more thing's like the npc and their teammates?

local ray = Ray.new(script.Parent.Head.CFrame.p, (TargetEnemy.Torso.Position - script.Parent.Head.CFrame.p).unit * 300)  -- ignore the targetenemy
local part, position = workspace:FindPartOnRay(ray, game.Workspace.Allies and game.Workspace.Ignore, false, true) -- problem
-- right from the wiki ;)

1 answer

✓ Accepted answer

Use FindPartOnRayWithIgnoreList. Instead of supplying a single argument to ignore, it allows you to supply it with an array filled with things you want it to ignore. I edited your code into an example below:

local ray = Ray.new(script.Parent.Head.CFrame.p, (TargetEnemy.Torso.Position - script.Parent.Head.CFrame.p).unit * 300)  -- ignore the targetenemy

local part, position = workspace:FindPartOnRayWithIgnoreList(ray, {workspace.Allies, workspace.Ignore}, false, true)

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