We present a technique for increasing the internal quality factor of kinetic inductance detectors (KIDs) by nulling ambient magnetic fields with a properly applied magnetic field. The KIDs used in this study are made from thin-film aluminum, they are mounted inside a light-tight package made from bulk aluminum, and they are operated near $150 , mathrm{mK}$. Since the thin-film aluminum has a slightly elevated critical temperature ($T_mathrm{c} = 1.4 , mathrm{K}$), it therefore transitions before the package ($T_mathrm{c} = 1.2 , mathrm{K}$), which also serves as a magnetic shield. On cooldown, ambient magnetic fields as small as approximately $30 , mathrm{mu T}$ can produce vortices in the thin-film aluminum as it transitions because the bulk aluminum package has not yet transitioned and therefore is not yet shielding. These vortices become trapped inside the aluminum package below $1.2 , mathrm{K}$ and ultimately produce low internal quality factors in the thin-film superconducting resonators. We show that by controlling the strength of the magnetic field present when the thin film transitions, we can control the internal quality factor of the resonators. We also compare the noise performance with and without vortices present, and find no evidence for excess noise beyond the increase in amplifier noise, which is expected with increasing loss.