'self' nil value, i don't understand

I’m decently new to LUA, so i’ve been going through doing tutorials, and i’ve been hand typing all of it, not copy pasting, so i understand a lot of the basics.
Right now i’m working on SWEPS, specifically an explode at target on the secondary fire, and then a regular primary for the 357. I’m copying most of my code directly from the tutorial, just typing it myself, but changing some stuff i know won’t affect the code or give me errors. Take a look at this

function SWEP.PrimaryAttack() – when +attack1 happens

–Make sure we can shoot first if ( !self:CanPrimaryAttack() ) then return end
if ( !self:CanPrimaryAttack() ) then return end

local bullet = {} – creates a table for the properties of the bullet
bullet.Num = self.NumBul – number of bullets you are shooting
bullet.Src = self.Owner:GetShootPos() – source, where your standing
bullet.Dir = self.Owner:GetAimVector() – direction of bullet, where your looking
bullet.Spread = Vector( self.Spread, self.Spread, 0 ) --spread of bullet, how accurate spread is
bullet.Tracer = 0 – no effect
bullet.Force = self.Force – how powerful it is
bullet.Damage = self.Damage – how much damage it does to people
bullet.AmmoType = self.Primary.Ammo – what type of ammo used

self.Owner:FireBullets( bullet ) – actually shoots the bullet

self:EmitSound ( self.Sound )
– this makes the sound, specified earlier

self.BaseClass.ShootEffects (self);
– this makes the shooting animation for the 357 view/world model

self:SetNextPrimaryFire( CurTime() + self.Delay )
self:SetNextSecondaryFire( CurTime() + self.Delay )
–sets time for next fire

self:TakePrimaryAmmo(1) – removes 1 ammo from clip when shot
end

I’m getting errors for ‘self’ being a nil value all the way down, if i erase a line itll just give me the same error for the next line. This is the primary fire code, i used self in the secondary fire code and it works fine, its just the primary fire, heres my secondary fire code

function SWEP:SecondaryAttack()

if ( !self:CanPrimaryAttack() ) then return end

local eyetrace = self.Owner:GetEyeTrace();

self:EmitSound ( self.Sound )

self.BaseClass.ShootEffects (self);

local explode = ents.Create( “env_explosion” ) – creates the explosion
explode:SetPos( eyetrace.HitPos )
– This creates the explosion through your get eye trace, thats why its in front
explode:SetOwner( self.Owner ) – This sets you as the person who made the explosion
explode:Spawn() – This actually spawns the explosion
explode:SetKeyValue( “iMagnitude”, “220” ) – The magnitude
explode:Fire( “Explode”, 0, 0 )
explode:EmitSound( “weapon_AWP.Single”, 400, 400 ) – Sound for explosion, and how far away it can be heard

self:SetNextPrimaryFire( CurTime() + self.Delay )
self:SetNextSecondaryFire( CurTime() + self.Delay )
– This sets the delay for the next fires

self:TakePrimaryAmmo(1) – removes 1 ammo from our clip

end – end of function

How can i fix this? And if you give me a fix, can you please explain why this fixes it? I’m trying to learn

self.Owner

‘function SWEP.PrimaryAttack()’ should be ‘function SWEP**:**PrimaryAttack()’

Fixed, thanks guys, had to change my error in the SWEP:PrimaryAttack() , then change the GetShootPos and GetAimVector to self.Owner: