Joining / Connecting Issue

Hi, I’m having an issue when making my hud.
While the player is connecting, the console is spammed with this error:

 [ERROR] addons/darkrpmodificationaddon/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:57: attempt to index field 'DarkRPVars' (a nil value)
  1. v - addons/darkrpmodificationaddon/lua/darkrp_modules/hudreplacement/cl_hudreplacement.lua:57
   2. unknown - lua/includes/modules/hook.lua:84

Then, when the player spawns and is able to move around, the errors stop, and the hud displays correctly with no errors from that point on.
This only happens when A player is connecting.

My attempt to fix this was adding…

 if !LocalPlayer():IsValid() then return end 

However, it didn’t seem to make a difference. I also tried placing it above the DrawHud function, but in that instance, there were no errors, but the hud never displayed at all.

This is my current code, with all of my hud drawings removed.

Which default HUD elements should be hidden?

local hideHUDElements = {
	-- if you DarkRP_HUD this to true, ALL of DarkRP's HUD will be disabled. That is the health bar and stuff,
	-- but also the agenda, the voice chat icons, lockdown text, player arrested text and the names above players' heads
	["DarkRP_HUD"] = true,

	-- DarkRP_EntityDisplay is the text that is drawn above a player when you look at them.
	-- This also draws the information on doors and vehicles
	["DarkRP_EntityDisplay"] = false,

	-- DarkRP_ZombieInfo draws information about zombies for admins who use /showzombie.
	["DarkRP_ZombieInfo"] = false,

	-- This is the one you're most likely to replace first
	-- DarkRP_LocalPlayerHUD is the default HUD you see on the bottom left of the screen
	-- It shows your health, job, salary and wallet, but NOT hunger (if you have hungermod enabled)
	["DarkRP_LocalPlayerHUD"] = true,

	-- If you have hungermod enabled, you will see a hunger bar in the DarkRP_LocalPlayerHUD
	-- This does not get disabled with DarkRP_LocalPlayerHUD so you will need to disable DarkRP_Hungermod too
	["DarkRP_Hungermod"] = false,

	-- Drawing the DarkRP agenda
	["DarkRP_Agenda"] = false

-- this is the code that actually disables the drawing.
hook.Add("HUDShouldDraw", "HideDefaultDarkRPHud", function(name)
	if hideHUDElements[name] then return false end


The Custom HUD
only draws health

surface.CreateFont( "Legacy", {
    font = "Tahoma",
    size = 16,
    weight = 5000,
    blursize = 0
} )

local function DrawHud()
if !LocalPlayer():IsValid() then return end

    local Health = LocalPlayer():Health()
    if Health <= 0 then Health = 0
    local Wallet = LocalPlayer()

    local Job = LocalPlayer().DarkRPVars.job

    local Salary = LocalPlayer().DarkRPVars.salary
    local FPS = math.Round(1 / FrameTime())

-- All of my hud elements such as text drawing and box drawing is here.
hook.Add("HUDPaint", "DarkRP_Mod_HUDPaint", DrawHud)

function hidehud(name)
	for k, v in pairs({"CHudHealth", "CHudBattery"})do
		if name == v then return false end
hook.Add("HUDShouldDraw", "HideOurHud:D", hidehud)

local function DisplayNotify(msg)
    local txt = msg:ReadString()
    GAMEMODE:AddNotify(txt, msg:ReadShort(), msg:ReadLong())

    MsgC(Color(255, 20, 20, 255), "[DarkRP] ", Color(200, 200, 200, 255), txt, "
usermessage.Hook("_Notify", DisplayNotify) 

Use getDarkRPVar instead.


(may not fix the issue, but use it anyway)

Oh my lord. It was that simple? Thank you so much. :slight_smile: SOLVED. :smiley: