gamemodes/desire/gamemode/cl_init.lua:4: attempt to index a nil value

I’m getting this error, when I shouldn’t (in theory) be.


gamemodes/desire/gamemode/cl_init.lua:4: attempt to index a nil value

VIP table (in shared.lua)


VIP = {}

VIP[0] = {
    name = "No VIP",
    salaryboost = 1,
    doorPrice = 120,
    doorReturn = 0.25,
    extraBaseWeapons = {},
    extraCopWeapons = {}
}
VIP[1] = {
    name = "Bronze VIP",
    salaryboost = VIP[0].salaryboost + 0.20,
    doorPrice = 110,
    doorReturn = 0.35,
    extraBaseWeapons = {"weapon_physgun"},
    extraCopWeapons = {}
}
VIP[2] = {
    name = "Silver VIP",
    salaryboost = VIP[1].salaryboost + 0.20,
    doorPrice = 100,
    doorReturn = 0.45,
    extraBaseWeapons = {},
    extraCopWeapons = {}
}
VIP[3] = {
    name = "Gold VIP",
    salaryboost = VIP[2].salaryboost + 0.20,
    doorPrice = 90,
    doorReturn = 0.55,
    extraBaseWeapons = {},
    extraCopWeapons = {}
}
VIP[4] = {
    name = "Diamond VIP",
    salaryboost = VIP[3].salaryboost + 0.20,
    doorPrice = 80,
    doorReturn = 0.65,
    extraBaseWeapons = {},
    extraCopWeapons = {}
}
VIP[5] = {
    name = "Staff VIP",
    salaryboost = VIP[4].salaryboost + 0.20,
    doorPrice = 70,
    doorReturn = 0.75,
    extraBaseWeapons = {},
    extraCopWeapons = {}
}

Line the error relates to (cl_init.lua)


    draw.WordBox( 8, 5, ScrH() / 1.38, "VIP: "..VIP[LocalPlayer():GetNetworkedInt("VIP")].name, "Default", Color(50,50,75,100), Color(255,255,255,255) )


Code to get VIP level (sv_modules/PlayerSaveData.lua):


     

   vip_level = sql.QueryValue("SELECT vip_level FROM desire_ply_info WHERE unique_id = '"..steamID.."'")

ply:SetNWInt("VIP", vip_level)

If i do:


lua_run RunConsoleCommand('say', VIP[1].name)

in my server console it provides me the name.

Try ensuring that the GetNWInt is returning what you want. I know that there are times when LocalPlayer is not valid during loading.
Perhaps try using
[lua]VIP[LocalPlayer():GetNetworkedInt(“VIP”) or 0][/lua]
to set a default value so that you’ll never try indexing by a nil value. This could help while loading.

Thanks, I’ll try this.

I’m still getting that error.

When I try to get the info from client, I get this.

Problem is the NWInt isn’t being set, make sure that you’re setting it correctly.

That is the thing, Im setting it fine, the same command works serverside too! (Replacing LocalPlayer() with Entity(1))

Wait a second, are you sure that the VIP table is accessible from the client? Try printing it.


] lua_run_cl print(VIP)
table: 0x2334ca40



] lua_run_cl print(VIP[1].name)
Bronze VIP



] lua_run_cl print(VIP[1].salaryboost)
1.2


Bearing in mind, the salaryboost is using



 VIP[0].salaryboost + 0.20

Gonna undig this from the pile of threads it is covered in.

Any ideas?

It’s possible that your HUD file is being loaded before the VIP tables etc or NWInts have been loaded from their files. Try encasing your function to draw the VIP stats with checks to ensure that values have been loaded, something like this:
[lua]if VIP and LocalPlayer():GetNWInt( “VIP” ) then
– draw text
end[/lua]
If this is the case you would only get the error a couple of times after you load.
You should also check your include()s to make sure that you’re loading the file with VIP stuff before the HUD file.
You might also want to check if LocalPlayer() is valid beforehand also, since there’s times when the HUD loads before the localplayer is fully loaded.