Yes you can. Local firearms laws need to be met but residency in a state is not usually required. Most do a phone in backgroud check to a federal database, fill out the local forms ( sometimes for the county). Pistols are NOT supposed to be transported across state lines by the purchasers. They need to be shipped or sent to a licensed dealer in the state where the purchaser is resident, for logging into that dealers log.Usually another background check is done and another set of local paperwork completed.
Its legal to buy guns in another state. We do have an INterstate Commerce Claus in the US Constitution, so such sales cannot be prohibited, but the transport of arms can be regulated.
We do it all the time between New Hampshire and Vermont.
Its required here from FFls but I spose you can buy privately from a regular citizen and wade thru the interstate transport of firearms laws on your way home.
I hate all these laws but ya gotta deal with them