Get more information on a hit part when using :FindPartOnRayUsingWhitelist

I am raycasting out of the bottom of a ball to check if a part on a whitelist is beneath it. The whitelist contains terrain and any part within a folder named “Water”.

I can say


which gives me the name of what it hits, whether it be terrain or water. But I have no idea how to compare the hit’s value to the whitelist table. For instance, how would I check if the hit was terrain or water? It tells me in the print, but I dont know how to check because the hit doesnt have a name or anything thats obvious.

EDIT: Nevermind, I cant get the name of a nil value. :sunglasses:

The hit is the most obvious thing though. It’s literally the object that your ray hits. It’ll be workspace.Terrain if it was terrain and a part named “Water” for whatever water part it hits. If you want to differentiate it then just know that Terrain is the only one with the water material property; the material enum is something the function returns as well.

Another thing is that the function also returns your position of contact, the normal of the surface that it hits, and the material of whatever it hits (as explained above). It gives plenty of information about whatever you hit, even when you don’t hit anything.

PS. It’s “FindPartOnRayWithWhitelist” :wink:

1 Like

Did you know that :FindPartOnRayWithWhitelist not only returns hit, but these values:

The BasePart (or Terrain ) hit, the Vector3 point of intersection, the Vector3 surface normal at the point of intersection and the Material of the BasePart or terrain cell hit.

Quoted from the wiki

Yep, I think here the relevant return value here would be the material. Water is a material, not a completely separate entity from terrain, so that should be easy.