Can you raycast through a transparency threshold

So, before I make this a suggestion.

I don’t want to on a game join find all transparent parts and store them, I think it will be a pain, what if an scripts makes new parts? Or what if there’s a lot of transparency parts, this would just slow down the initial loading time.

Without using collision groups or a massive list on join (or same principle every raycast) how can you efficiently do a raycast through a transparent part?

To elaborate, if I wanted to raycast through a part that has transparency set to 0.9, how would I do that without the above? Is it possible?

So you want a ray to detect only parts with transparency set to .9, or you want a ray to detect parts with transparency set to .9? Cause im pretty sure rays already do the latter

Ignore, proceed, go through a part with a particular transparency.

I don’t need this for anything right now but, for instance if I wanted to set a border to transparency 1 and have can collide on, the raycast wouldn’t go beyond that.

Unless theres a method to go through a transparency

Well the only ways I can think of is with an ignore list or turn CanQuery of all parts of a particular transparency to false. You can make a premade list or folder in the workspace. Or have a script check all descendants for that along with a ChildAdded event to check for new ones. Or a combination of both. I can’t think of a simpler way to achieve that.

You could add to the filter which parts are not .9

local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Exclude
RayParams.FilterDescendantsInstances = {}

local Raycast = workspace:Raycast(Vector3.new(), Vector3.new(), RayParams)
-- add your own direction and origin

if Raycast and Raycast.Instance then
	local part: BasePart = Raycast.Instance
	if part.Transparency ~= 0.9 then
		RayParams:AddToFilter({part})
	end
end

You could try something like this:
Raycast once. Check the transparency of the detected instance. If the transparency is not equal to 0, then raycast again in the same direction as the original raycast, but starting from the position where the original raycast ended. Repeat this until you find a part that isn’t transparent.

Raycast cost is based almost entirely on the distance you go, so it’s fine to split the raycasts from a performance perspective.

When I need this I make a custom raycast function that automatically skips over parts with certain properties by going along the raycast path and recasting from the hit point if the hit object is something to be ignored (e.g. transparent).

Here is a function I found

-- By Nube762
-- Modified by BendsSpace
function RayCast(p,dir,ignore, transparency)
   local Rayparams = RayCastParams.new()
   Rayparams.FilterType = Enum.RaycastFilterType.Blacklist
   Rayparams.FilterDescendantsInstances = ignore
   local ray = workspace:RayCast(p,dir,Rayparams)
   if ray and ray.Instance and ray.Instance.Transparency <= transparency then
      local clone = {unpack(ignore)}
      table.insert(clone,ray.Instance)
       return RayCast(p,dir,clone)
  end
  return ray
end

Source: Creating a ray that automatically ignores transparent parts - #8 by Nube762 (a slightly different method using the ignore list, though still perfectly fine)

If you search “devforum raycast function ignore transparent” you should get some threads and different functions.