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.