FindPartOnRayWithIgnoreList Material Argument

  1. What do you want to achieve? I want to Raycast and ignore the glass material

  2. What is the issue? Is this possible?

  3. What solutions have you tried so far? I Googled but I didn’t find out if you can put a material Enum as ignore

You can perhaps search for all glass material parts in the workspace and put them in the ignore table.

Create a recursive function with an ignore list as a parameter.
Do the usual ray stuff however if the ray hit a part which is made out of glass, put that part in the ignore list table and call the function again with the ignore list.

Oh, that makes sense. Will probably post a feature request for this tho so that it doesn’t have to be more complicated than it needs to be

Following @BBQIsTasty’s idea, but with a more optimised approach, you can just use :FindPartOnRayWithIgnoreList() normally, put it in a repeat loop until the part that it returns isn’t a glass material, and each time the part is put into an ignore table.

local ignore = {}
local ray = this would be your ray
repeat 
   local part = workspace:FindPartOnRayWithIgnoreList(ray, ignore)
   table.insert(ignore, part)
until part.Material == "Glass"
table.remove(#ignore) --after we found the part that isn't a glass material, we would remove the last member of the table (which is the part that wasn't glass, because we add them no matter what)

You could just add every single glass part to your ignore list and go from there. No need for a loop or anything of that sort. For doing this, I recommend CollectionService.

2 Likes

In addition to what colbert2677 has said, I recommend using this plugin to add CollectionService tags:

1 Like

To optimize this I would probably raycast from the place that the ray hit the glass part, so that you aren’t repeatedly doing long ray casts and instead doing shorter ray casts.

1 Like