Getting Config errors when adding GM.CivilProtection

Alright so I need to add some custom civil protection like my Fireman and SWAT but it’s been glitchy, sometimes it works and sometimes it doesn’t and I’m literally changing nothing.

Here’s my code:

GM.CivilProtection = {
        [TEAM_POLICE] = true,
        [TEAM_CHIEF] = true,
        [TEAM_MAYOR] = true,
        [TEAM_SWAT] = true

The error I get:

ERROR gamemodes/darkrp/gamemode/config.lua283: table index is nil
1. unknown  - gamemodes/darkrp/gamemode/config.lua283
2. include - [C]:-1
3. unknown - gamemodes/darkrp/gamemode/cl_init.lua:60

Not sure why this keeps happening, I’ve checked my team names and they’re fine.

This means at the point your code is executing, one of those four values is nil. Are you doing this before or after you declare your teams?

My shared.lua is done and dusted, I haven’t made any changes to it.
Do you mean the position of the code in the actual config.lua?

Are TEAM_POLICE, TEAM_CHIEF, TEAM_MAYOR, and TEAM_SWAT defined before this? The reason you would get this error is one ( or all ) of them are not - likely because the those values are being defined in a file that is included later.

The error occurs originally on my TEAM_POLICE. I have placed this GM.CivilProtection at the bottom of config.lua, should I move it further up or move it to a different file completely?

Is config.lua loaded before or after the TEAM_ values are defined? Just at any point after they exist is fine.

I’m not sure which is executed first, config.lua or shared.lua. I imagine it’s probably config.lua, I’ll have a little play around and get back to you.

EDIT: I moved GM.CivilProtection to my shared.lua and it worked! Thanks man, I owe you