Need help with table.Random

I have a “Loot Crate” entity in my gamemode currently that gives a random weapon from a table:

function ENT:AcceptInput( name, activator, caller )
	if name == "Use" and caller :IsPlayer() then
		weapon = { "weapon_scrappistol", "weapon_scrapsmg", "weapon_scrapshotgun", "weapon_scraprifle", "weapon_scrapsniper" }
		caller:Give( table.Random( weapon ) )
		caller:ChatPrint( "The common loot crate contained: " .. table.Random( weapon ) .. " and $500!" )
		caller:Money_Add( 500 )
		Entity( 1 ):EmitSound( "doors/door_screen_move1.wav" )
		Entity( 1 ):EmitSound( "vo/npc/male01/yeah02.wav" )

It works great accept I want the ChatPrint to print the same gun name that you get, at the moment they are both completely random and not connected. Anyone know how I could do this?

Thanks in advance.

Make a local variable that’s table.Random(weapon) and use that for Give and ChatPrint

Is this not right? Getting errors

		weapon = { "weapon_scrappistol", "weapon_scrapsmg", "weapon_scrapshotgun", "weapon_scraprifle", "weapon_scrapsniper" }
		local gun( table.Random( weapon ) )
		caller:Give( gun )
		caller:ChatPrint( "The common loot crate contained: " .. gun .. " and $500!" )


[ERROR] gamemodes/rogue/entities/entities/ent_lootcrate1/init.lua:20: syntax error near 'caller'
  1. unknown - gamemodes/rogue/entities/entities/ent_lootcrate1/init.lua:0

Sorry, am noob

[editline]1st September 2016[/editline]

Ok nvm, I got it. I’m an idiot. Thanks a lot :slight_smile: