The fungus gnats larvae will feed on & damage plant roots. The larvae needs damp/wet soil, which suggest you are over watering the potted plants (root rot).
Use Flying Insect spray to control the adult gnat. See
https://www.planetnatural.com/pest-p...-gnat-control/ for control of the gnat larvae.