Ore generation, Ray detecting mountain surface

Problem
I want to achieve my ore surface to detect the meshpart mountains top surface and orientation and return the position.

At the moment, my code only makes it so the ore duplicates at the bottom face of the mesh mountain:


image

		local XRAND = math.random(Material[3],Material[4])
		local ZRAND = math.random(Material[5],Material[6])
		OreBP.Position = Vector3.new(XRAND, 500, ZRAND)
		
		local testRay = Ray.new(OreBP.Position, OreBP.Position - OreBP.CFrame.UpVector * 1000)
		local hitPart, hitPosition = workspace:FindPartOnRay(testRay, OreBP)

		if hitPart then
			--print(hitPart:GetFullName())
			hit, position, normal = workspace:FindPartOnRay(testRay, OreBP)
			--print(position)
			local hitCFrame = CFrame.new(Vector3.new(XRAND, position.Y, ZRAND), position+normal)
			Ore:SetPrimaryPartCFrame(hitCFrame *CFrame.Angles(-math.rad(90),0,0))
		end
4 Likes