Fixing a SWEP

I’m currently trying to get throwable glowsticks on my ttt server. The problem I’ve run into is that they have unlimited ammo, you can just keep throwing them, I’ve tried a couple of things but nothing has worked.
This is the code I have:
[lua] if (SERVER) then

AddCSLuaFile( "shared.lua" )

resource.AddFile(“models/glowstick/v_glowstick_ylw.mdl”)
resource.AddFile(“models/glowstick/stick_ylw.mdl”)
resource.AddFile(“materials/models/glowstick/glow_ylw.vtf”)
resource.AddFile(“materials/models/glowstick/01.vtf”)

SWEP.Weight				= 5
SWEP.AutoSwitchTo		= true
SWEP.AutoSwitchFrom		= true

end

if ( CLIENT ) then

language.Add (“ent_glowstick_fly”, “Glow Stick Yellow”)
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModelFOV = 56
SWEP.ViewModelFlip = false
SWEP.CSMuzzleFlashes = false
SWEP.HoldType = “slam”
SWEP.PrintName = “Glow Stick”
SWEP.Author = “Patrick Hunt”
SWEP.Base = “weapon_tttbase”
SWEP.Slot = 2
SWEP.SlotPos = 5

end

SWEP.Author = “Patrick Hunt”
SWEP.Contact = “Patrick06Hunt@gmail.com
SWEP.Purpose = “”
SWEP.Instructions = “LMB - Drop lighitng glow stick.”
SWEP.Base = “weapon_tttbase”
SWEP.HoldType = “slam”
SWEP.Category = “Glow Sticks”

SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.ViewModel = “models/glowstick/v_glowstick_ylw.mdl”
SWEP.WorldModel = “models/glowstick/stick_ylw.mdl”

SWEP.Primary.ClipSize = 4
SWEP.Primary.DefaultClip = 4
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “none”
SWEP.Primary.Delay = 2

SWEP.Secondary.ClipSize = 0
SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “none”
SWEP.Secondary.Delay = 2

function SWEP:Think()
end

function SWEP:Initialize()
//util.PrecacheSound(self.Primary.Sound);
self:SetWeaponHoldType( self.HoldType )
end

function SWEP:Deploy()
self.Weapon:SendWeaponAnim(ACT_VM_DRAW);
self.Weapon:SetNextPrimaryFire(CurTime() + 1.75)
return true
end

function SWEP:Reload()
return true
end

function SWEP:PrimaryAttack()
self.Weapon:SendWeaponAnim( ACT_VM_SECONDARYATTACK )
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)

self:TakePrimaryAmmo(1)
	
	timer.Simple(0.5, function()
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
			if SERVER then
				local ent = ents.Create("ent_glowstick_ylw_fly")
			
			ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
			ent:SetAngles(self.Owner:EyeAngles())
			ent:Spawn()
			ent:Activate()
							
			local phys = ent:GetPhysicsObject()
			phys:SetVelocity(self.Owner:GetAimVector() * 125)
			phys:AddAngleVelocity(Vector(math.random(-1000,1000),math.random(-1000,1000),math.random(-1000,1000)))
		end
	end)
		timer.Simple(1, function()
		self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
		end)

end

function SWEP:SecondaryAttack()
self.Weapon:SendWeaponAnim( ACT_VM_THROW )
self.Weapon:SetNextSecondaryFire(CurTime() + self.Secondary.Delay)

self:TakePrimaryAmmo(1)

	timer.Simple(0.5, function()
	self.Owner:SetAnimation( PLAYER_ATTACK1 )
			if SERVER then
				local ent = ents.Create("ent_glowstick_ylw_fly")
			
			ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16))
			ent:SetAngles(self.Owner:EyeAngles())
			ent:Spawn()
			ent:Activate()
							
			local phys = ent:GetPhysicsObject()
			phys:SetVelocity(self.Owner:GetAimVector() * 500)
			phys:AddAngleVelocity(Vector(math.random(-1000,1000),math.random(-1000,1000),math.random(-1000,1000)))
		end
	end)
		timer.Simple(1, function()
		self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
		end)

end

function SWEP:Holster()
return true
end

function SWEP:OnRemove()
return true
end
[/lua]



if ( self.Weapon:Clip1() <= 0 ) then return end


Yep, you aren’t actually checking whether you have enough ammo or not, you are just calling TakePrimaryAmmo and continuing. However, your primary ammo type is set to “none”, so I’m not sure how that works.

I just want to point this out to avoid future errors. In the primary attack you are starting a timer and in the timer you are using self and self.Owner without checking if they are valid. If someone attacks then disconnects before the timer runs, you’ll get errors in the server console.

EDIT:

And you can (should?) just use self instead of self.Weapon