Q. How did Gentiles obtain salvation before Christ?
A. In the beginning there was only one race of mankind and they all knew God. After the flood, God separated people into different races by family (Genesis 10) and as they separated some fell away from God in favor of religions they invented to replace Him.
Later, God called Abraham for the purpose of making His descendants the people through whom the world could obtain salvation.
During all this time if people retained the belief that God would one day send a redeemer to save them from their sins as He had promised to their forefathers, they would receive eternal life.
Also, in Romans 2:14 Paul said the requirements of the Law are written on our hearts, so even those don’t who know the Law, intuitively know how God wants us to live.
This combination of faith and works eventually evolved into the Levitical system through which people could come to the Lord for salvation until Jesus died for the sins of the world.