Salary returning nil

alright, so, this little shit wont work.

[lua]TEAM_DB = {}
function GM:LoadTeams(tbl)
TEAM_DB[tbl.ID] = tbl
print(“Loaded “…tbl.Name…” team.”)
team.SetUp(tbl.ID, tbl.Name, tbl.Color)
end

function Player:Salary()
return TEAM_DB[self:Team()].Salary
end[/lua]

Heres the team,

[lua]
TEAM = {}

TEAM.ID = 1
TEAM.Name = ‘Patriot’
TEAM.Ref = ‘team_pat’
TEAM.Salary = 50
TEAM.Color = Color(0, 208, 255)
TEAM.Loadout = { weapon_key }
TEAM.Desc = [[A normal citizen, who supports the rebellion.]]
GM:LoadTeams(TEAM)
[/lua]

The error is this, attempting to index a nil value shared.lua (first lua code i put)

Anyone known why? Salary is clearly not nil… this also prints in my console,
Loaded Patriot team so I know the team is loading.

Also, Player is the meta table.

Add print(self:Team()) to the Salary function

Worked, but when I try’d to put that on my hud, got the same error again -.-
[lua]
draw.SimpleText(‘Salary: $’…ply:Salary(), ‘ChatFont’, 30, ScrH()-65, Color(217, 28, 255))
[/lua]

Also, this wont work as well,
[lua]
function Player:Teamname()
return team.GetName(self:Team())
end
[/lua]
it just prints this on the hud, Team:
does not put the team name there. :expressionless:

Entity:Team() returns an entity. I asked you to add the print so that you could tell me what printed in the console.

It prints 1, the patriot team.

It’s probably because the HUD starts drawing before the server sets the player’s team.

You could maybe do something like this if it fits your needs

[lua]function Player:Salary()
local res = TEAM_DB[self:Team()]
if res == nil then
return 0
end
return res.Salary
end[/lua]

Edit: Before somebody bothers, yes this will only prevent erroring if another hook is using Player.Salary before the teams are setup.