KeyPress Problem

Hi all,

So I’m using the hook “KeyPress” and what I want it to do is if a player is looking at a vehicle and presses R it opens the menu. I’ve done that but the problem is that after I have pressed R on the car and the menu opens, everytime I look at the car the menu opens without pressing R.

Here’s my current code:

local function CarPress( ply, key )
	if not key == IN_RELOAD then return end
	if ply:GetEyeTrace().Entity:GetClass() == "prop_vehicle_jeep"then
			net.WriteEntity( ply:GetEyeTrace().Entity )
hook.Add("KeyPress", "poopoohook", CarPress )

So how do I make it so only when I press R while look at the car it opens and then after it doesn’t unless they press R again


How about doing a bit of debugging, considering all of your code seems to be fine.
Print every time that your player receives the net message. If that’s normal, then it’s something to do with your client side code.
Also, you should localize the player’s eye trace, because if the player presses reload while not looking at an entity then you’ll get a Lua error saying that GetClass or Entity is a nil value or something.

Try PlayerBindPress; KeyPress can be inconsistent when other keys are pressed.

the IN_SPEED key by keypressed is what key to PlayerBindKey is it the +speed or the -speed
found it somewhere here