If key pressed, remove entity

Hello, I want to remove an entity when a key for example KEY_1 is pressed, I found some code that I can use to achieve this.



function TOOL:Holster()
		if IsValid( self.GhostEntity ) then 
                    self.GhostEntity:Remove() 
                end
	end


I want to be able to use that code to run self.GhostEntity:Remove() when a key is pressed.


hook.Add( "KeyPress", "RemoveEntity", function( ply, key )
   if ( key == KEY_1 ) then
      -- remove entity here. self will not work since there is no parent; you'll probably need to use ents.Find
   end
end )

Am I right in thinking I should use ents.FindByName(“GhostEntity”)?

[editline]4th September 2015[/editline]

At the moment I have this code:



hook.Add( "KeyPress", "RemoveEntity", function( ply, key )
   if ( key == KEY_1 or key == KEY_2 or key == KEY_3 or key == KEY_4 ) then
      print(ents.FindByName("GhostEntity"))
      ents.FindByName("GhostEntity"):Remove()
   end
end )


I get the error that remove is a nil value.

A screenshot of my issue:

im not sure what im doing is the best way to solve it, but all I basically want to do, is make that object get removed, when I switch to a weapon (basically, press KEY_1 etc)