There’s one other important facet of Acts 2:38 that needs to be pointed out: more than a command, it’s a promise.
We focus on what it tells people that they are to do. Peter’s focus (Luke’s focus, and therefore, the Holy Spirit’s focus) was on the wonderful things that God had to offer to his people. They could receive forgiveness of sins. They could receive the Holy Spirit living within.
“Peter replied, “Repent and be baptized, every one of you, in the name of Jesus Christ for the forgiveness of your sins. And you will receive the gift of the Holy Spirit. The promise is for you and your children and for all who are far off—for all whom the Lord our God will call.”” (Acts 2:38–39)
Don’t think of it as a command. Think of it as a promise.