It just might be your head, I had that exact same trouble with my current gf in the beginning, still do from time to time but it’s getting better.
If possible try to be under her for the initial penetration, this worked for me ‘cause I noticed that if I was lying down and ‘got up’ to penetrate her in say, missionary. I would go flaccid during the ‘getting up’-part.
But if I’m below and she’s on top it’s all a bit easier since you won’t need to concentrate on anything else but just having it up until it goes in :)
If you find it hard to get in when your below, try getting a good grip around the base of your penis just before penetration, should get the blood to stay in a bit longer at least, and once you’re inside it’s very hard to get flaccid.
Unless you are extremely stressed or concerned :) So just try to relax mentally, hard as hell in the beginning but you’ll get there ;) If you have an understanding girlfriend you can try an ancient Chinese technique called ‘soft penetration’.
Basically you put it in using your finger and gently rub it into an erection. This might not work if you’re young ‘cause a lot of young girls have trouble accepting ‘weird’ things in bed :)
Hope any of what I wrote helped :P