Why is self a nil value?

Here is the code for my SWEP’s secondary and reload functions.

Looks fine to me, but when I try to right click and/or reload I get

[…lua:54] attempt to index global ‘self’ (a nil value)
[…lua:68] attempt to index global ‘self’ (a nil value)

In the code, line 54 corresponds to the first line of the SecondaryAttack function, and line 68 corresponds to the first line of the Reload function.

[lua]
function SWEP.SecondaryAttack()
self.Weapon:SetNextSecondaryFire(CurTime()+0.5)
local current=(self.Owner:Health())
local max=(self.Owner:GetMaxHealth())
local pitch=(100+math.Round((current/max)*0.5))
if (current<max) then
self.Weapon:EmitSound(WinSound,50,pitch)
self.Owner:SetHealth(current+1)
self.Weapon:SetClip1(self.Weapon:Clip1()-1)
else
self.Weapon:EmitSound(FailSound,50,100)
end
end

function SWEP.Reload()
local trace=(self.Owner:GetEyeTrace())
if (trace.HitPos:Distance(self.Owner:GetShootPos())<=70) then
local ent=(self.Owner:GetEyeTrace().Entity)
if ((ent:IsValid())and((ent:IsPlayer())or(ent:IsNPC()))) then
local current=(ent:Health())
local max=(ent:GetMaxHealth())
local percentage=(math.Round(max/current))
self.Owner:PrintMessage(HUD_PRINTTALK, “Scans indicate this individual is " … percentage … " percent healthy.”)
else
self.Owner:PrintMessage(HUD_PRINTTALK, “No target.”)
end
end
end
[/lua]

Any idea why?

You’re using SWEP**.Reload and SWEP.**SecondaryAttack.

Use, SWEP**:Reload and SWEP:**SecondaryAttack

Notice the : not .

Thanks, I’m such a dumbass.

It’s a common mistake, : just tells it to pass self automatically so

function ENT:MyFunc(player) is the same as function ENT.MyFunc(self, player)