KeyPress HUD Code Help.

so there is some networking needed for what I am trying to do, and uhhh… the most i’ve ever networked was sending 2 player names to the client, so I need some help.

Anyways, some of you know that on surf or bhop servers, you can view what keys(usually w,a,s,d,crouch) the player you are spectating is pressing. I am trying to minimalistically recreate that. I had a friend code this for me yesterday, but he wants $10 for it(for less than an hour work of code). So nobody is paying $10 and this is for anybody that wants to adapt this into whatever they want to do with it.

Before you read the code, the issue I am having is the KeyDown or KeyPressed functions I have tried to use are not working by theirself client side, so I am assuming they need some networking to solve this.



--[[
if SERVER then
	
	util.AddNetworkString("leftpress")
	util.AddNetworkString("rightpress")
	util.AddNetworkString("forwardpress")
	util.AddNetworkString("backpress")
	hook.Add("Tick", "KeyPressChecks", function()
		local ply = LocalPlayer()
		local ply2 = ply:GetObserverTarget()
		net.Start("forwardpress")
			if ply2:KeyPressed( IN_FORWARD ) then
				net.WriteString(unfinished)
			end
		net.Broadcast()

		
	end )

	
	
end 
]]

if CLIENT then
	
	function SpectatorKeyHud()
		local ply = LocalPlayer()
		local ply2 = ply:GetObserverTarget()
		
		
		if ply:GetObserverMode() == OBS_MODE_IN_EYE or OBS_MODE_CHASE and not ply2 == ply then
			
			draw.RoundedBox(0, 60, ScrH() - 150, 20,20, Color(25,25,25))
			if ply2:KeyDown( IN_FORWARD ) then
				draw.SimpleText("W", "Trebuchet24",61, ScrH() - 152, Color(255,0,0))
			else
				draw.SimpleText("W", "Trebuchet24",61, ScrH() - 152, Color(255,255,255))
			end
			
			draw.RoundedBox(0, 40, ScrH() - 130, 20,20, Color(25,25,25))
			if ply2:KeyDown( IN_LEFT ) then
				draw.SimpleText("A", "Trebuchet24",43.75, ScrH() - 132, Color(255,0,0))
			else
				draw.SimpleText("A", "Trebuchet24",43.75, ScrH() - 132, Color(255,255,255))
			end
	
			draw.RoundedBox(0, 60, ScrH() - 130, 20,20, Color(25,25,25))
			if ply2:KeyDown( IN_BACK ) then
				draw.SimpleText("S", "Trebuchet24",63.75, ScrH() - 132, Color(255,0,0))
			else
				draw.SimpleText("S", "Trebuchet24",63.75, ScrH() - 132, Color(255,255,255))
			end
			
			draw.RoundedBox(0, 80, ScrH() - 130, 20,20, Color(25,25,25))
			if ply2:KeyDown( IN_RIGHT ) then
				draw.SimpleText("D", "Trebuchet24",83.75, ScrH() - 132, Color(255,0,0))
			else
				draw.SimpleText("D", "Trebuchet24",83.75, ScrH() - 132, Color(255,255,255))
			end
			
			--else return
			
		end
	end
	hook.Add("HUDPaint", "Spec", SpectatorKeyHud)
	
end


What I was originally trying to do, was every time ply2 would press w, a, s, or d, that key would highlight(really just change colors) to red.

I’ve just about tried all my luck with the very little networking I know how to do and I can’t pull any good results.
I will add the crouch keypress to the hud, but I just want to get these to work for now.

I realize everything I have said above may not make complete sense because I didn’t thoroughly explain anything really, so lmk if you need some clarification.

first, you should remove everything except ply & ply2 from the think hook, it is useless waste of ‘calculation’. Then, afaik, no networking is needed, since KeyDown is shared. But if I remember right, you need a fully own spectating system, where you set wich observer mode the player gets upon entering spectator, then when pressing X key(like switching to next player etc) and so on. It should work in TTT though.