HUD Problem

Hi, I’m trying to make a new HUD but I’m getting an error saying


247] attempt to concatenate global 'v1' (a nil value)(Hook: HUDPaint)
[DarkRP\gamemode\client\hud.lua:247] attempt to concatenate global 'v1' (a nil value)(Hook: HUDPaint)
[

This error relates to line 32 in the code below. I was wondering if anyone knew what was up with it and how to fix it?

[LUA]local function DoActualHUD()

--If the variables table has not be initialized, initialize it
LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {}

--If the money is not set, don't do anything
local v1 = LocalPlayer().DarkRPVars.money
if not v1 then v1 = "" end

--If the salary is not set, don't do anything
local v2 = LocalPlayer().DarkRPVars.salary
if not v2 then v2 = "" end

end

local function DrawHUD()

Scrw, Scrh = ScrW(), ScrH()
RelativeX, RelativeY = 0, Scrh

--Draws the box and colors it
draw.RoundedBox(5, 25, ScrH() - 175, 200, 150, Color(25,25,25,200))
surface.SetDrawColor(255,255,255)

--Displays player Icon and displays player name
surface.SetTexture(surface.GetTextureID("gui/silkicons/user"))
surface.DrawTexturedRect(25 + 10,ScrH() - 160,16,16)
draw.SimpleText(LocalPlayer():Nick(),"TargetID", 25 + 30,ScrH() - 165, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

surface.SetTexture(surface.GetTextureID("gui/silkicons/money"))
surface.DrawTexturedRect(25 + 10,ScrH() - 140,16,16)
draw.SimpleText("$" .. v1,"TargetID", 25 + 30,ScrH() - 145, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

surface.SetTexture(surface.GetTextureID("gui/silkicons/group"))
surface.DrawTexturedRect(25 + 10,ScrH() - 100,16,16)
draw.SimpleText(LocalPlayer().DarkRPVars.job,"TargetID", 25 + 30,ScrH() - 105, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

[/LUA]
Thanks in advance

Can anyone help me with this problem?

Are you running DarkRP on the server you’re running it on?

Yes

On the code you posted line 31, you are doing “”$" … v1". v1 is a nil value. You are not setting it in your doActualHUD function because it’s a local. Do this instead:

[lua]
local function DoActualHUD()

--If the variables table has not be initialized, initialize it
LocalPlayer().DarkRPVars = LocalPlayer().DarkRPVars or {}

--If the money is not set, don't do anything
local v1 = LocalPlayer().DarkRPVars.money
if not v1 then v1 = "" end

--If the salary is not set, don't do anything
local v2 = LocalPlayer().DarkRPVars.salary
if not v2 then v2 = "" end

return v1,v2
end

local function DrawHUD()

local v1,v2 = DoActualHUD()

Scrw, Scrh = ScrW(), ScrH()
RelativeX, RelativeY = 0, Scrh
 
--Draws the box and colors it
draw.RoundedBox(5, 25, ScrH() - 175, 200, 150, Color(25,25,25,200))
surface.SetDrawColor(255,255,255)

--Displays player Icon and displays player name
surface.SetTexture(surface.GetTextureID("gui/silkicons/user"))
surface.DrawTexturedRect(25 + 10,ScrH() - 160,16,16)
draw.SimpleText(LocalPlayer():Nick(),"TargetID", 25 + 30,ScrH() - 165, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
 
surface.SetTexture(surface.GetTextureID("gui/silkicons/money"))
surface.DrawTexturedRect(25 + 10,ScrH() - 140,16,16)
draw.SimpleText("$" .. v1,"TargetID", 25 + 30,ScrH() - 145, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
 
surface.SetTexture(surface.GetTextureID("gui/silkicons/group"))
surface.DrawTexturedRect(25 + 10,ScrH() - 100,16,16)
draw.SimpleText(LocalPlayer().DarkRPVars.job,"TargetID", 25 + 30,ScrH() - 105, Color(255,255,255), TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

[/lua]

Here I am setting the values, and should work normally.

Thanks James, thats fixed it