The effect of ambipolar resistivity on the formation of dense cores