The Railgun is one of the most powerful weapons in the Grand Theft Auto series, capable of obliterating vehicles and enemies with a single shot. In GTA 5 and GTA Online, the Railgun is a special weapon that can be obtained through various methods, depending on whether you're playing in story mode or online.
For story mode, the Railgun is only available to returning players who have transferred their progress from the PS3 or Xbox 360 versions to the PS4 or Xbox One. However, in GTA Online, any player can access the Railgun during certain missions and game modes, regardless of their returning player status.
There is no current workaround method (or cheat code) to obtain the rail gun, other than the legitimate methods stated below.
Returning Player Requirement
You can obtain the Railgun in both GTA 5 story mode as well as GTA Online.
However, to get it in story mode, you must be a returning GTA player. A returning GTA player is someone who played the PS3 or Xbox 360 version of the game and moved their account to the PS4 or Xbox One.
In GTA Online you can access the Railgun regardless of whether you are a returning player not. However, you can only access it in certain missions, since it is too powerful and would otherwise give you an unfair advantage over other players. In story mode you can use it whenever you want.
Story Mode
There are several locations where you can find the Railgun in GTA 5's story mode, which are as follows:
Minor Turbulence
In Story Mode, if you are a returning player, you can easily buy the Railgun through any Ammu-Nation after completing the main story mission 'Minor Turbulence'. It will be available to purchase for $250,000.
Once you complete Minor Turbulence, head over to the crash site of the airplane from the mission at Alamo Sea. You will find a Railgun in the cockpit section of the wrecked plane. It is highly recommended that you first obtain a Scuba Diving Gear and then head over to the location, as the wreckage is deep underwater.