I need a toggleable effect

I’m trying to have reaload key toggle between the following variables in a swep

ply:SetRenderMode(RENDERMODE_NORMAL)
ply:SetColor(Color(255, 255, 255, 255))

ply:SetRenderMode(RENDERMODE_TRANSALPHA)
ply:SetColor(Color(0, 0, 0, 50))

please help with what code will alow the user toggle between these two

Serverside only. (lua/autorun/server – for example)



hook.Add( 'KeyPress', 'KeyPress.ToggleColorRenderMode', function( _Player, _Key )
	if ( _Key == IN_RELOAD ) then
		_Player.ColorRenderToggle = _Player.ColorRenderToggle || false
         
		if _Player.ColorRenderToggle then
			_Player:SetRenderMode( RENDERMODE_TRANSALPHA )
			_Player:SetColor( Color( 0, 0, 0, 50 ) )
		else
			_Player:SetRenderMode( RENDERMODE_NORMAL )
			_Player:SetColor( Color( 255, 255, 255, 255 ) )
		end

		_Player.ColorRenderToggle = !_Player.ColorRenderToggle
	end
end )


Tahnks :slight_smile:

What’s with the underlines and capitals? Is this what the cool kids are doing these days

Some strange style I picked up over time from VB.net, but then again I’m also dumb