function GetTerrainForMouse(Z)local y=(game:GetService("\087\111\114\107\115\112\097\099\101")).Terrain:WorldToCellPreferSolid(Vector3.new(Z.hit.x,Z.hit.y,Z.hit.z))local F=nil local g=nil if 0==((game:GetService("\087\111\114\107\115\112\097\099\101")).Terrain:GetCell(y.X,y.Y,y.Z)).Value then y=nil F,g=PlaneIntersection(Vector3.new(Z.hit.x,Z.hit.y,Z.hit.z))if g then y=F end end return y end
-- Purpose:
-- Checks for terrain touched by the mouse hit.
-- Will do a plane intersection if no terrain is touched.
--
-- mouse - Mouse to check the .hit for.
--
-- Return:
-- cellPos - Cell position hit.  Nil if none.
function GetTerrainForMouse(mouse)
	-- There was no target, so all it could be is a plane intersection.
	-- Check for a plane intersection.  If there isn't one then nothing will get hit.
	local cell = game:GetService("Workspace").Terrain
		:WorldToCellPreferSolid(Vector3.new(mouse.hit.x, mouse.hit.y, mouse.hit.z))
	local planeLoc = nil
	local hit = nil
	-- If nothing was hit, do the plane intersection.
	if 0 == game:GetService("Workspace").Terrain:GetCell(cell.X, cell.Y, cell.Z).Value then
		cell = nil
		planeLoc, hit = PlaneIntersection(Vector3.new(mouse.hit.x, mouse.hit.y, mouse.hit.z))
		if hit then
			cell = planeLoc
		end
	end
	return cell
end
