need help burst fire SWEP

this bit of code was suppose to make my gun fire in a burst but does not it shoots nothing on my screen.


function SWEP:PrimaryAttack()
if burst < 3 then
local burst = burst + 1
timer.Simple( 0.18, self.PrimaryAttack, self )
else local burst = 1
end
end

full code



if SERVER then
   AddCSLuaFile( "shared.lua" )
end

if CLIENT then
   SWEP.PrintName = "FAMAS"
   SWEP.Slot      = 2 

   SWEP.ViewModelFOV  = 72
   SWEP.ViewModelFlip = false
end

SWEP.Base				= "weapon_tttbase"



SWEP.HoldType			= "ar2"

SWEP.Primary.Delay       = 0.11
SWEP.Primary.Recoil      = 0.804
SWEP.Primary.Automatic   = true
SWEP.Primary.Damage      = 23
SWEP.Primary.Cone        = 0.025
SWEP.Primary.Ammo        = "smg1"
SWEP.Primary.ClipSize    = 20
SWEP.Primary.ClipMax     = 60
SWEP.Primary.DefaultClip = 20
SWEP.Primary.Sound       = Sound( "Weapon_FAMAS.Single" )

SWEP.IronSightsPos = Vector (-4.6856, 0, 1.144)
SWEP.IronSightsAng = Vector (0, 0, -1.2628)

SWEP.ViewModel  = "models/weapons/v_rif_famas.mdl"
SWEP.WorldModel = "models/weapons/w_rif_famas.mdl"
resource.AddFile("models/weapons/v_rif_famas.mdl")
resource.AddFile("models/weapons/w_rif_famas.mdl")

SWEP.Kind = WEAPON_HEAVY


SWEP.AutoSpawnable = true


SWEP.AmmoEnt = "item_ammo_smg1_ttt"


SWEP.IsSilent = false


SWEP.NoSights = false

function SWEP:PrimaryAttack()
if burst < 3 then
local burst = burst + 1
timer.Simple( 0.18, self.PrimaryAttack, self )
else local burst = 1
end
end

Only calling primaryattack on the clientside doesn’t call it on the serverside. You should have the PrimaryAttack function be shared.

It is shared code that he posted.

Additionally, don’t have it call itself, you can use a bullet to lob 3 at a time if you want, or allow the user to hold the button ( think recursively ) until the burst has been achieved. Let go of trigger = reset count.

[lua]if burst < 3 then
local burst = burst + 1
timer.Simple( 0.18, self.PrimaryAttack, self )
else local burst = 1[/lua]

You are using burst before it’s defined anywhere, then defining it as local within the if block. Learn about variable scoping.

This is a trickier problem than it sounds to solve, but I believe I have achieved it in the past y firing the bullets in the think hook and have primary attack initiate the firing