Attempt to index global (a nil value)

Greetings.

After a longer break, I have now started programming again. I am coding a traitor weapon and ran into the error above.

Here is the full error:

[ttt2-wep_anti-randomat_revamped] addons/ttt2-wep_anti-randomat_revamped/gamemodes/terrortown/entities/weapons/weapon_ttt2_anti_randomat/shared.lua:79: attempt to index global 'AntiRandomat' (a nil value)
  1. unknown - addons/ttt2-wep_anti-randomat_revamped/gamemodes/terrortown/entities/weapons/weapon_ttt2_anti_randomat/shared.lua:79

I know what the error means, but I don’t know why it’s printed. The part it’s pointing at, is this one:

function SWEP:PrimaryAttack()

    if SERVER and IsFirstTimePredicted() then

        AntiRandomat:TriggerEvilEvent(self.Owner)

        DamageLog("ttt2_weapon_antirandomat_log" .. self.Owner:Nick() .. " (" .. self.Owner:GetRoleString() .. ").") 

        self:SetNextPrimaryFire(CurTime() + 10)

        self:Remove()  

    end

end

The function “AntiRandomat:TriggerEvilEvent(ply)” is located in another file, it looks like this:

function AntiRandomat:TriggerEvilEvent(ply)

    if table.Count(AntiRandomat.EvilMapEvents) == 0 then AntiRandomat.EvilMapEvents = table.Copy(AntiRandomat.EvilEvents) end

    local evs = AntiRandomat.EvilMapEvents

    local indices = e_eventIndices()

    randomizeTable(events_probabilites)

    local e_event = get_random_event()

    AntiRandomat.RunningEvilEvents[indices] = e_event

    AntiRandomat.RunningEvilEvents[indices].Ident = indices

    AntiRandomat.RunningEvilEvents[indices].Owner = ply 

    AntiRandomat:EventAnnouncement(AntiRandomat.RunningEvilEvents[indices].Title)

    AntiRandomat.RunningEvilEvents[indices]:Boot()

    if AntiRandomat.RunningEvilEvents[indices].Time ~= nil then

        timer.Create("Anti-Randomat" .. AntiRandomat.RunningEvilEvents[indices].Ident, AntiRandomat.RunningEvilEvents[indices].Time or 60, 1, function()

            AntiRandomat.RunningEvilEvents[indices]:Terminate()

            AntiRandomat.RunningEvilEvents[indices] = nil

        end)

    end

    AntiRandomat.EvilMapEvents[e_event.Id]

end

If you need all the code, to understand everything, I can give you the link to the addon’s github repository:

Thanks in Advance for any help.

You cannot create functions (<table>:<function>) like this without using a metatable.
I advise you to replace that with a (<table>.<function>) which in the end will not change strictly anything to the execution of your function but you will have to replace the : with a .
For more information, I advise you to consult these two ([1], [2]) topics.

Ah thanks. I will look into it, when I am at home.