I watched this movie a long time ago, probably it’s from 80s or 90s. The kids have imaginary friends (which is common even in real life) and they are taken to the doctor by parents, but the imaginary friends tell kids not to take pills otherwise they (friends) will disappear, something like that.
This sounds like Drop Dead Fred released in 1991.
General premise is that an adult woman who is having a bad time finds her childhood imaginery friend, Drop Dead Fred.
There is one part in the movie that involves a doctor prescribing medication to children with imaginery friends.
Worried by Elizabeth's recent strange behavior, Polly brings her to a (children's) psychologist. In the waiting room, Fred is seen meeting up with the imaginary friends of other patients, who are all children. The doctor prescribes medication to rid her of Fred, whom he and Polly believe is a figment of her imagination.