If you're getting a lot of foam, that's co2 coming out of solution which will cause flat/under carbonated bottles. Also, if you have to release the pressure in the keg, that can cause flat beer because the pressure is no longer keeping the co2 IN the beer.