Best way of removing this entity?

Hello, I want to remove the following floating object when the player, switches to a weapon, and I was wondering how I could do this.

Screenshot: http://steamcommunity.com/sharedfiles/filedetails/?id=512143425

The code I am trying to use, does not work.



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


I am using this script to control switching weapons: http://forum.facepunch.com/showthread.php?t=1484243

[editline]4th September 2015[/editline]

Anyone got an idea?

Any errors? Optimize the code(I dont know if it affects it) - put spaces between if and the (, same with the end. Plus it checks if you got the toolgun(if I am right) equiped, then the code will be run, else not.

It only checking if I have the custom tool gun is what I want, spaces dont matter

Well in the image you dont have it equipped if I am right.

Its just that the second if doesnt seem to run.

[editline]4th September 2015[/editline]

yes, that is my issue, when I switch to a weapon, the entity should be removed

The code should:

check if the player has the custom toolgun.
then, check if the player switches to another weapon(I use the keys 1,2,3,4 to switch to the others with my custom script)
then, should remove the entity GhostEntity, which is the floating object you see in the image