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)

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

Heres the team,

TEAM = {}

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.]]

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 -.-
draw.SimpleText(‘Salary: $’…ply:Salary(), ‘ChatFont’, 30, ScrH()-65, Color(217, 28, 255))

Also, this wont work as well,
function Player:Teamname()
return team.GetName(self:Team())
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
return res.Salary

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