Also I thought you could receive communion as long as you say the penitential prayer at the beginning of Mass.
Is this not the case?
Nope. You have to be absolved in the Sacrament of Reconciliation/Penance (Confession) before you can receive Holy Communion. The reason is that you are only supposed to receive Holy Communion and have a moral certainty that you are in what's called a 'state of grace', i.e. the Holy Spirit is abiding in you. The lack of this state of grace comes from committing what's called 'mortal sin', i.e. a grave sin with full knowledge / consent. Homosexual acts would constitute a mortal sin, therefore you would not be in a state of grace, therefore not prepared to receive Holy Communion.
St. Teresa describes the soul in a state of mortal sin as like a crystal with a black cloth thrown over it so that no light can get in / out of it.
Being in this state is spiritual death; it means that if you died right now, in a state of mortal sin, you would go immediately to hell. In order to go to heaven, you must be in a state of grace, with the Holy Spirit abiding in you, in a state of friendship with God.
I only say this to motivate you to go to confession, for the sake of your soul and your salvation. When your soul is not in a state of grace you are separated from Christ and cannot perform prayer / spiritual actions in the most perfect manner. Basically, you need to confess.
Prayer for the grace of contrition for your sins, and the courage to go to confession. Do not receive Holy Communion until you have confessed. Do not conceal any mortal sin in confession, as that would invalidate the sacrament and constitute another grave sin. Pray to the Blessed Virgin. Look up one of the ancient virgin martyrs like St. Cecilia, Agnes, Lucy, Agatha, Barbara, Anastasia, Philomena, Dorothy, Margaret, etc., and pick one to be your patron in your struggle against unchastity. Pray to them for the grace of repentance and purity. God bless you.