The gang carried a handgun, a crowbar and a machete as they burst into the Kirkcaldy home of Dwayne Kinner, who was with his cousin Nicholas Roberts.
James Mackie, 30, Derek Finlay, 31, Gordon Ellis, 24, and Scott Smith, 23, raided the flat on 8 January 2015.
A stolen phone with a tracking app took the police to the gang.
They also made off with a haul of Â£2,500.
The High Court in Edinburgh heard that the victims believed they were going to be shot after the gun was pointed at their heads and another robber threatened he was going to cut their fingers off.
The gun, which was discovered to be an air pistol, was later found behind a kickboard in a kitchen at a house in Glenrothes, which Finlay had previously had access to.
Advocate Ashley Edwards QC said it had the appearance of a firearm.
Mackie, from Kirkcaldy, Ellis, from Cardenden, Finlay, a prisoner and Smith, from Cardenden, all pleaded guilty to assaulting and robbing the victims.
Judge Michael O'Grady QC deferred sentence for the preparation of background reports and all four were remanded in custody.

Amnesty International supporters are zipped into some of the bags in the first few rows, alongside a banner saying #DontLetThemDrown.
Bags are lined up in rows in front of the East Sussex resort's Big Wheel close to the pier.
The protest comes ahead of an EU leaders' meeting over the crisis.
David Cameron will attend the summit in Brussels, which will discuss a response to the growing problem.
Amnesty UK director Kate Allen said: "Until now, the UK government's response has been shameful but finally they have been woken up to the need to act.
"EU governments must now urgently turn their rhetoric into action to stop more people drowning on their way to Europe."
Four thieves who forced their way into a Fife flat and held two men at gunpoint while they stole money and valuables have admitted the raid.
[NEXT_CONCEPT]
Two hundred body bags have been placed on Brighton beach in a protest to highlight the UK's response to the migrant crisis in the Mediterranean.