Peter is saying that those who heed the gospel message of repentance from sin and faith in the sacrifice of Christ will begin to live lives of obedience to God's commandments, and thus He gives them His Spirit. However, some contend that it is not that simple.
One of the objections that has been raised to this understanding of this verse is that it is impossible to obey God before receiving His Spirit. Therefore, it would be impossible to receive God's Spirit if obedience were a requirement.
Acts 2:38 gives two basic requirements for receiving the Holy Spirit: 1) repentance and 2) faith in the sacrifice of Christ. (Baptism is an outward confession of this faith in Christ's sacrifice.) Repentance is a deep and genuine feeling of remorse over having committed sins, bringing about the suffering and death of Jesus Christ. It is accompanied by an urgent desire to make the necessary changes in our life so we avoid committing the same sins again. In other words, true repentance brings about an earnest desire to obey God. In turn, this earnest desire causes us to begin to make changes in our lifestyle to conform to God's commandments.
When John the Baptist preached a message of repentance to prepare the way for Jesus Christ, he demanded that his followers make changes in their lives (Luke 3:8). When John was preaching, the Holy Spirit had not yet been given, but John made it clear that God expected the people to begin changing their lives to demonstrate that their repentance was genuine. Paul preached the exact same message regarding repentance before King Agrippa (Acts 26:20).
A truly repentant person will immediately begin striving to obey God. The changes that the individual makes in his life are the "fruits" that demonstrate that his repentance is genuine. This does not mean that the repentant sinner obeys God perfectly. Even those who have received the Holy Spirit do not obey God perfectly. It means that the individual has turned his life around and is oriented toward obeying God. Upon producing the fruits of repentance and demonstrating faith in the sacrifice of Christ through baptism, God gives him His Holy Spirit. As Peter simply stated, God gives His Holy Spirit to those who obey Him!
Some contend that the obedience mentioned in this scripture is that of obeying God's command to preach the gospel, not obeying God's laws. Proponents of this explanation argue that Peter's statement came about because the authorities called the apostles into account for disobeying their command not to preach about Jesus. This derives from Peter's comment in verse 29, "We ought to obey God rather than men."
There are a number of problems with this interpretation. First, it ignores the clear requirements God lays down for receipt of the Holy Spirit—repentance and faith in the sacrifice of Christ. Nowhere in the Scripture does God require the preaching of the gospel as a prerequisite for receiving His Spirit. Rather, the power of the indwelling Spirit of God inspired and motivated the apostles to preach the gospel after they had received the Spirit (Acts 2:4). Furthermore, this interpretation ignores the overall thrust and context of Peter's statement (Acts 5:30-31).