We analyze the processes governing cosmic-ray (CR) penetration into molecular clouds and the resulting generation of gamma-ray emission. The density of CRs inside a cloud is depleted at lower energies due to the self-excited MHD turbulence. The depletion depends on the effective gas column density (size) of the cloud. We consider two different environments where the depletion effect is expected to be observed. For the Central Molecular Zone, the expected range of CR energy depletion is $Elesssim 10$ GeV, leading to the depletion of gamma-ray flux below $E_gammaapprox 2$ GeV. This effect can be important for the interpretation of the GeV gamma-ray excess in the Galactic Center, which has been revealed from the standard model of CR propagation (assuming the CR spectrum inside a cloud to be equal to the interstellar spectrum). Furthermore, recent observations of some local molecular clouds suggest the depletion of the gamma-ray emission, indicating possible self-modulation of the penetrating low-energy CRs.