Raycast colliding with non-whitelisted part

Hi, so im using raycast to spawn parts, i used raycast whitelist to add a folder and now the ores spawn on the grass/green part


The problem is that the raycast also spawns them inside the stone for example.
How do i make it so the raycast doesn’t work if it collides with a non-whitelisted part?

If you make a part non-whitelisted It will not be seen on the ray.
What I would do is to not have a whitelist and check if what the part hits is the grass.

I think you set the folder as non whitelisted. Loop through all the children of the folder, check if its a basePart and if it is add it to the list. You can also use blacklist too.

Simple. Whitelist the rock, so that the ray stops if it hits the rock. Then check if it hit the rock, and ignore the raycast if it hits.

I think there is a simple misunderstanding at play here. Unwhitelisted parts simply will not collide with the ray, so if you want to detect if the ray hits something else, for example so you can ignore the raycast if it hits the rock, the rock needs to be “whitelisted” as well. Even if you aren’t going to spawn on a rock if you hit it.

Yeah i didn’t think about that. Oops
Im now using an if statement like
if raycastResult.Instance.Parent = game.workspace.Ground then

Thanks