Hud wont show my box

This is the code for my hud when I am ingame there is nothing there it is just a plain screen and I dont know why



function myhud()

	local client = LocalPlayer()
	if not client:Alive() then return end
	if (client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end

draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255))
draw.SimpleText(client:Health() .. "%", "ScoreboardText", 100, 50, Color(86, 104, 86, 255), 0, 0)

	local mag_left = client:GetActiveWeapon():Clip1() 
	local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) 
	local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType())
end

hook.Add("HUDPaint", "myhud", myhud)

local tohide = { -- This is a table where the keys are the HUD items to hide
	["CHudHealth"] = true,
	["CHudBattery"] = true,
	["CHudAmmo"] = true,
	["CHudSecondaryAmmo"] = true
}
local function HUDShouldDraw(name) 
	if (tohide[name]) then     
		return false;      
	end
end
hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw)
hook.Add("HUDPaint", "myhud", myhud)
 
local tohide = { 
	["CHudHealth"] = true,
	["CHudBattery"] = true,
	["CHudAmmo"] = true,
	["CHudSecondaryAmmo"] = true
}
local function HUDShouldDraw(name) 
	if (tohide[name]) then     
		return false;      
	end
end
hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw)

Where do you have the file located?
It has to be in your “lua/autorun/client” directory,
unless you are doing something with a gamemode.

The files are in the right place but it doesn’t show anything on my screen like any boxes , or traces of anything

What gamemode is this for though?

Its just for practice I have it in garrysmod/lua/autorun/client so it will use it for sandbox but when I start the single player game there it no Hud and I don’t get any errors so I dont know why

It probably isn’t running because there’s an error or 7. There’s a lot of things wrong with this code.
I’m assuming you should be getting a “tried to compare entity with nil” or maybe with string error.

Your code. I added in some comments to tell you what you are doing wrong.



function myhud()
    local client = LocalPlayer()
    if not client:Alive() then return end
    if (client:GetActiveWeapon() == NULL or client:GetActiveWeapon() == "Camera") then return end  -- Don't use "NULL", Lua uses "nil"

draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255))                                -- Try to space your code properly, makes it easier to read, and easier to edit.
draw.SimpleText(client:Health() .. "%", "ScoreboardText", 100, 50, Color(86, 104, 86, 255), 0, 0)

    local mag_left = client:GetActiveWeapon():Clip1() 
    local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType())      -- I assume you will use these later.
    local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType())
end

hook.Add("HUDPaint", "myhud", myhud)  -- The FIRST HUDPaint hook.

local tohide = { -- This is a table where the keys are the HUD items to hide
    ["CHudHealth"] = true,
    ["CHudBattery"] = true,
    ["CHudAmmo"] = true,
    ["CHudSecondaryAmmo"] = true
}
local function HUDShouldDraw(name) 
    if (tohide[name]) then     
        return false;      
    end
end
hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw)  -- Your FIRST HUDShouldDraw hook.
hook.Add("HUDPaint", "myhud", myhud)    -- the SECOND HUDPaint hook. You will only need 1, since you are basically hooking the same function twice. Potentially why your shit ain't working.
 
local tohide = { 
    ["CHudHealth"] = true,
    ["CHudBattery"] = true,
    ["CHudAmmo"] = true,
    ["CHudSecondaryAmmo"] = true
}
local function HUDShouldDraw(name) 
    if (tohide[name]) then     
        return false;      
    end
end
hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw) -- Your SECOND HUDShouldDraw hook. YOU ONLY NEED ONE.


I reworked your code.



function myhud()
    local client = LocalPlayer()
    if not client:Alive() then return end
    if (client:GetActiveWeapon() == nil or client:GetActiveWeapon() == "Camera") then return end

    draw.RoundedBox(3, 5, 5, 200, 100, Color(51, 58, 51, 255))
    draw.SimpleText(client:Health() .. "%", "ScoreboardText", 100, 50, Color(86, 104, 86, 255), 0, 0)

    local mag_left = client:GetActiveWeapon():Clip1() 
    local mag_extra = client:GetAmmoCount(client:GetActiveWeapon():GetPrimaryAmmoType()) 
    local secondary_ammo = client:GetAmmoCount(client:GetActiveWeapon():GetSecondaryAmmoType())
end

hook.Add("HUDPaint", "myhud", myhud)

local tohide = { -- This is a table where the keys are the HUD items to hide
    ["CHudHealth"] = true,
    ["CHudBattery"] = true,
    ["CHudAmmo"] = true,
    ["CHudSecondaryAmmo"] = true
}

local function HUDShouldDraw(name) 
    if (tohide[name]) then     
        return false;      
    end
end

hook.Add("HUDShouldDraw", "How to: HUD Example HUD hider", HUDShouldDraw)


Ok now I get this error and they just keep popping up
[ERROR] lua/autorun/client/cl_hud.lua:8: attempt to index global ‘client’ (a nil value)

  1. unknown - lua/autorun/client/cl_hud.lua:8

Here is my code


draw.SimpleText(client:Health() .. "%", "default", 100, 50, Color(86, 104, 86, 255), 0, 0)

Replace client with LocalPlayer()

I give up, you are useless.

edit:
All it takes is a simple google search, you don’t need the whole populous of FP to see your lack of simple LUA,

Learn from this #1 : http://www.lua.org/manual/5.1/
Learn from this #2 : http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7a06.html