Make ray ignore part with specific name

I want to make my raycast ignore the part that have child name “NoDetect” but I don’t know how to do that

so I can do something like this :
image

thx

check the docs for workspace:Raycast. The 3rd param is a RaycastParams. That RaycastParams object has a member named ‘FilterDescendantsInstances’. This is a table of instances to ignore.

If you’re using whitelist, you can loop over workspace and exclude the parts that has a child with the specific name from the FilterDescendantsInstances property.

local param = RaycastParams.new()
param.FilterType = Enum.RaycastFilterType.Whitelist

local filter_table = {}

for _, i in pairs(workspace:GetDescendants()) do
  if i:IsA('BasePart') and not i:FindFirstChild('NoDetect') then --checks if instance is a part and it does NOT have a child named "NoDetect"
    table.insert(filter_table, i)
  end
end

param.FilterDescendantsInstances = filter_table

If you would like to use blacklist then it’s the opposite:

local param = RaycastParams.new()
param.FilterType = Enum.RaycastFilterType.Blacklist

local filter_table = {}

for _, i in pairs(workspace:GetDescendants()) do
  if i:IsA('BasePart') and i:FindFirstChild('NoDetect') then --checks if instance is a part and HAS a child named "NoDetect"
    table.insert(filter_table, i)
  end
end

param.FilterDescendantsInstances = filter_table

Side note: If you’re using value instances to determine whether or not a part should be ignored, you should consider using attributes instead. They’re much simpler and faster than using separate instances.

5 Likes

Can also use a collision group or collection service.