KeyPress/KeyRelease Spazzing Out

Trying to make a toggle when IN_RELOAD is pressed to switch a networked boolean between true and false. No matter how I coded it, it seems to just spaz out and repeat itself three our four times. Which makes coding a toggle next to impossible because it rapidly switches between true and false a couple times whenever the key is pressed. Any ideas how to prevent this?

I tried input.IsKeyDown but it won’t broadcast a networked boolean from a HUDPaint hook, and input.IsKeyDown returns a “Attempt to index global ‘input’ a nil value” error when on a Think hook.

Corner… I am painted into one. :<



function toggle(pl,key)
	if key == IN_RELOAD then
		pl:SetNWBool("delete", false)
		pl:ChatPrint("0")
	end
end
hook.Add("KeyRelease", "toggle", toggle)




OUTPUT:

0
0
0


[lua]
local keysdown = {}
hook.Add(“KeyPress”,“dicks”,function(ply,key)
if !keysdown[key] then
keysdown[key] = true
–do your networking stuff here
end
end)
hook.Add(“KeyRelease”,“dicks”,function(ply,key)
if keysdown[key] then
keysdown[key] = false
–do your networking stuff here
end
end)
[/lua]

Put in ChatPrint commands for testing purposes. Still spams the heck out of everything.



local keysdown = {}
hook.Add("KeyPress","stuff",function(ply,key)
     if !keysdown[IN_RELOAD] then
          keysdown[IN_RELOAD] = true
		  ply:ChatPrint("RELOAD PRESS")
     end
end)
hook.Add("KeyRelease","stuff2",function(ply,key)
     if keysdown[IN_RELOAD] then
          keysdown[IN_RELOAD] = false
		  ply:ChatPrint("RELOAD RELEASE")
     end
end)


I just tested the code I told you on my end, and it worked perfectly fine. You’ve broken something somehow, or have some bad code in a file that’s being ran.

[editline]5th March 2015[/editline]

infact, my code wasn’t even necessary; the result was not spammed even just with an empty hook function doing a simple print

I will re-install a few things later today and remove some addons… and see if that helps. Mind me adding you to Steam perchance?

Those hooks mess up on a regular basis. It’s an old bug and it has been reported. You can also have them mess up if you hold a key and try pressing others.

-snip-