Weird DarkRP Error

Hey guys, I was coding my hud and I got spammed with this on the next rejoin:


[ERROR] gamemodes/darkrp/gamemode/client/hud.lua:267: attempt to index field 'DarkRPVars' (a nil value)
  1. DrawHUD - gamemodes/darkrp/gamemode/client/hud.lua:267
   2. oldFunc - gamemodes/darkrp/gamemode/client/hud.lua:463
    3. unknown - addons/dbugr/lua/dbugr/util/modules/sh_func.lua:77

This is line 267:


draw.SimpleTextOutlined("$ " .. LocalPlayer().DarkRPVars.money, "Hud2", ypos + 280, ScrH() - 26, Color(255, 255, 255, 200), 0, 0, 1, Color(0, 0, 0, 200))

The weird part is that it still fully works and everything, I just hate having an error. Its unprofessional if anything.

I also tried removing dbugr.

I am using DarkRP 2.4.3

Does the error get spammed all the time or only at certain times (eg. when joining)?

Only when the first few people join.

Try checking if the entity is valid before you paint it, and also, are you using HUDShouldDraw?

Yes I am

When a player joins, their DarkRPVars are not guaranteed to exist immediately. A safer way of accessing your DarkRPVars is:

[lua](ply:getDarkRPVar(“money”) or “”)[/lua]

In context that would be:

[lua]draw.SimpleTextOutlined("$ " … (LocalPlayer():getDarkRPVar(“money”) or “”), “Hud2”, ypos + 280, ScrH() - 26, Color(255, 255, 255, 200), 0, 0, 1, Color(0, 0, 0, 200))[/lua]

Oh thank you Bo98!