Hi I am trying to use FindPartOnRay() to detect terrain type of "Mud" but I keep getting "Air."
mouse.Move:Connect(function() local ray,point,surfaceNormal,material = game.Workspace:FindPartOnRay(Ray.new(game.Workspace.Camera.CFrame.Position,mouse.Hit.Position) print(material) end) --Always prints air, even when pointed at a plastic brick or Mud terrain
mouse.Move:Connect(function() local ray,point,surfaceNormal,material = game.Workspace:FindPartOnRayWithIgnoreList(mouse.UnitRay,{Enum.Material.Air}) print(material) end)
The "FindPartOnRayWithIgnoreList" is what you were looking for.
Also just found the possible reason why Enum.Material.Air does not work for an ignore list, it is set to not browsable https://wiki.roblox.com/index.php?title=API:Class_reference/ReflectionMetadata
I came up with another idea, but it didn't work, I'll put the code here anyway (it does work for other applications)
I made a region3 from the camera's position to the mouse position and used Terrain:ReadVoxels() to get the terrain along the path of the ray, but the problem in this case is that Enum.Material.Air is not able to be detected by ReadVoxels
mouse.TargetFilter = workspace.Part function ignoreList(first,last) local region = Region3.new(last, first) print(region.CFrame," SIZE ",region.Size) workspace.Part.CFrame=region.CFrame--this places a part in the middle of the region so you can visualize where the region is region = region:ExpandToGrid(4) local material,occupancy = game.Workspace.Terrain:ReadVoxels(region, 4) local size = material.Size local allMats = {} for x = 1, size.X do for y = 1, size.Y do for z = 1, size.Z do allMats[#allMats+1]=material[x][y][z] end end end return allMats end