I am making a pickaxe which will produce ores and minerals based on the material of the terrain the player clicks on. For example stone if the player clicks on stone, and salt if the player clicks on salt. I utilized the raycasting tutorial on the wiki, and almost got the function to work. The problem is that whenever a piece of terrain is clicked on, the script would print out "Plastic", and not the actual material of the terrain. Any ideas on what can be done to fix this?

if (cPosition - charPos).magnitude <= reach then --If area clicked is within the player's reach then mine the area
		t:FillBlock(CFrame.new(cPosition), area, Enum.Material.Air)
		
		local ray = Ray.new(charPos, (cPosition - charPos).unit * reach)--Creates ray to detect what material the terrain is
		local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
		
		if part then
			
			local terrain = part.Name == "Terrain"
		
			if terrain then
				print(part.Material.Name)
			end
			
		end
		
	end

2 comments

0

the script cant identify the material but it can find the color by doing pert:GetMaterialColor(Grass)

0

Have you tried making the third argument to true (terrainCellsAreCubes) (reference: https://developer.roblox.com/en-us/api-reference/function/Workspace/FindPartOnRay) ? Maybe that way it will detect terrain.