swep nil value

Hello,
I´m currently working on a SWEP addon, but it doesnt really work.
The console says: [ERROR] lua/poisongun.lua:25: attempt to index global ‘SWEP’ (a nil value)

  1. unknown - lua/poisongun.lua:25

My script:
if SERVER then
AddCSLuaFile( “poisongun.lua” )
end

if CLIENT then
SWEP.PrintName = “Posion Gun”
SWEP.Author = “Lutti”

SWEP.Purpose = "Poison an enemy, which deals 100 damage to him."
SWEP.Slot = 2
SWEP.SlotPos = 6
SWEP.Icon = "materials/Poison Gun/ttt_icon.png"

SWEP.ViewModelFOV = 50
SWEP.CSMuzzleFlashes = true

SWEP.EquipMenuData = {
type = "Weapon",
desc = "a poisonous gun that deals 100 dmg over time"
};

end

SWEP.Base = “weapon_tttbase”
SWEP.AutoSpawnable = false
SWEP.Spawnable = false
SWEP.AllowDrop = false
SWEP.isSilence = true
SWEP.Kind = WEAPON_EQUIP1

SWEP.ViewModel = “models/weapons/v_pistol.mdl”
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.UseHands = true

SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.LimitedStock = true

SWEP.Primary.Damage = 1
SWEP.Primary.ClipSize = 1
SWEP.Primary.ClipMax = 3
SWEP.Primary.DefaultClip = 3
SWEP.Primary.Ammo = “AR2AltFire”
SWEP.HeadshotMultiplier = 1
SWEP.Primary.Spread = 0.1
SWEP.Primary.Recoil = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Delay = 1.5

function SWEP:SetupDataTables()
self:NetworkVar( “Float”, 1, “NextIdle” )
end

function SWEP:Initialize()
self:SetHoldType( self.HoldType )
end

function SWEP:Shoot()
local cone = self.Primary.Cone
local bullet = {}
bullet.Num = self.Primary.NumShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Tracer = 1
bullet.Force = 1
bullet.Damage = self.Primary.Damage
bullet.TracerName = “AntlionGib”

self.Owner:FireBullets( bullet )
end

function SWEP:PrimaryAttack(worldsnd)

self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self:SetNextSecondaryFire( CurTime() + self.Primary.Delay )

if not self:CanPrimaryAttack() then return end

self.Owner:LagCompensation(true)

if not worldsnd then 
	self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK_SILENCED)
else 
	WorldSound(self.Primary.Sound, self:GetPos())
end

local Tracer = 1

self:Shoot()

if SERVER then 
if self.Owner:GetEyeTrace().HitNonWorld and self.Owner:GetEyeTrace().Entity:IsPlayer() then 

local en = self.Owner:GetEyeTrace().Entity
local uni = en:UniqueID() 
DamageLog("POISON:	 " .. self.Owner:Nick() .. " [" .. self.Owner:GetRoleString() .. "]" .. " poisoned " .. (IsValid(en) and en:Nick() or "<disconnected>") .." [" .. en:GetRoleString() .. "]" .. " with a Neurotoxin Gun.")
timer.Create(en:UniqueID(), 1, 99, function()

if IsValid(en) and en:IsTerror() then
if IsValid(self.Owner) then
en:TakeDamage(1,self.Weapon,self.Owner)

else
  en:TakeDamage(1,self.Weapon,self.Weapon)
end  

else
timer.Destroy(uni … “poisondart”)
end
end)

end
end
self:TakePrimaryAmmo(1)	

if isValid(self.Owner) then
	self.Owner:SetAnimation( PLAYER_ATTACK1 )

  self.Owner:ViewPunch( Angle( math.Rand(-0.8,-0.8) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )

end

self.Owner:LagCompensation(false)

end

function SWEP:GetHeadshotMultiplier()
return 0
end

function SWEP:Reload()
if ( GAMEMODE.Name == “Trouble in Terrorist Town” ) then return end
end

function SWEP:CustomAmmoDisplay()
self.AmmoDisplay = self.AmmoDisplay or {}

self.AmmoDisplay.Draw = false

return self.AmmoDisplay

end

function SWEP:WasBought(buyer)
if IsValid(buyer) then
buyer:GiveAmmo( 3, “AR2AltFire” )
end
end

Thank you for every help, I appreciate it a lot,
AllStarsAT

I said this in your last thread: put it in lua/weapons.

I did, still doesnt work.
I got it in here: E:\SteamLibrary\steamapps\common\GarrysMod\garrysmod\lua\weapons

Any errors?

yes, when i type in the console lua_openscript weapons/poisongun.lua, this message comes in the console :
] lua_openscript weapons/poisongun.lua
Running script weapons/poisongun.lua…

[ERROR] lua/weapons/poisongun.lua:25: attempt to index global ‘SWEP’ (a nil value)

  1. unknown - lua/weapons/poisongun.lua:25

[editline]29th January 2017[/editline]

Or do i have to spawn the weapon somehow else?

You don’t run the script manually. It should automatically be run, simply spawn the weapon from the spawn menu

how do i open the spawn menu i only paly ttt not sandbox
nvm got it, but the weapon isnt in the spawn menu
Forget all this above got it to work just got that one error left:
[ERROR] lua/weapons/weapon_poisongun.lua:76: attempt to call method ‘TakePrimaryAmmo’ (a nil value)

  1. unknown - lua/weapons/weapon_poisongun.lua:76

Script:

AddCSLuaFile()

if CLIENT then
SWEP.PrintName = “Posion Gun”
SWEP.Author = “Lutti”

SWEP.Purpose = "Poison an enemy, which deals 100 damage to him."
SWEP.Slot = 2
SWEP.SlotPos = 6
SWEP.Icon = "materials/Poison Gun/ttt_icon.png"

SWEP.ViewModelFOV = 50
SWEP.CSMuzzleFlashes = true

end

SWEP.Base = “weapon_tttbase”
SWEP.AutoSpawnable = false
SWEP.Spawnable = true
SWEP.AllowDrop = false
SWEP.isSilence = true
SWEP.Kind = WEAPON_EQUIP1

SWEP.ViewModel = “models/weapons/v_pistol.mdl”
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.UseHands = true

SWEP.CanBuy = { ROLE_TRAITOR }
SWEP.LimitedStock = true

SWEP.Primary.Damage = 1
SWEP.Primary.ClipSize = 3
SWEP.Primary.DefaultClip = 3
SWEP.Primary.Ammo = “AR2AltFire”
SWEP.HeadshotMultiplier = 1
SWEP.Primary.Spread = 0.1
SWEP.Primary.Recoil = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Delay = 1.5

function SWEP:SetupDataTables()
self:NetworkVar( “Float”, 1, “NextIdle” )
end

function SWEP:Shoot()
local cone = self.Primary.Cone
local bullet = {}
bullet.Num = self.Primary.NumShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Tracer = 1
bullet.Force = 1
bullet.Damage = self.Primary.Damage
bullet.TracerName = “AntlionGib”

self.Owner:FireBullets( bullet )
end

function SWEP:PrimaryAttack(worldsnd)

self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self:SetNextSecondaryFire( CurTime() + self.Primary.Delay )

self.Owner:LagCompensation(true)

if not worldsnd then 
	self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK_SILENCED)
else 
	WorldSound(self.Primary.Sound, self:GetPos())
end

local Tracer = 1

self:Shoot()
self:TakePrimaryAmmo( 1)

if SERVER then 
if self.Owner:GetEyeTrace().HitNonWorld and self.Owner:GetEyeTrace().Entity:IsPlayer() then 

local en = self.Owner:GetEyeTrace().Entity
local uni = en:UniqueID() 
DamageLog("POISON:	 " .. self.Owner:Nick() .. " [" .. self.Owner:GetRoleString() .. "]" .. " poisoned " .. (IsValid(en) and en:Nick() or "<disconnected>") .." [" .. en:GetRoleString() .. "]" .. " with a Neurotoxin Gun.")
timer.Create(en:UniqueID(), 1, 99, function()

if IsValid(en) and en:IsTerror() then
if IsValid(self.Owner) then
en:TakeDamage(1,self.Weapon,self.Owner)

else
  en:TakeDamage(1,self.Weapon,self.Weapon)
end  

else
timer.Destroy(uni … “poisondart”)
end
end)

end
end
	

if isValid(self.Owner) then
	self.Owner:SetAnimation( PLAYER_ATTACK1 )

  self.Owner:ViewPunch( Angle( math.Rand(-0.8,-0.8) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )

end

self.Owner:LagCompensation(false)

end

function SWEP:GetHeadshotMultiplier()
return 0
end

function SWEP:CustomAmmoDisplay()
self.AmmoDisplay = self.AmmoDisplay or {}

self.AmmoDisplay.Draw = false

return self.AmmoDisplay

end

function SWEP:WasBought(buyer)
if IsValid(buyer) then
buyer:GiveAmmo( 3, “AR2AltFire” )
end
end

function SWEP:CustomAmmoDisplay()

self.AmmoDisplay = self.AmmoDisplay or {}
self.AmmoDisplay.Draw = true
self.AmmoDisplay.PrimaryClip = self:Clip1()

return self.AmmoDisplay

end

Don’t know why that error would be happening, but you can redefine it in the weapon from the code provided here: https://wiki.garrysmod.com/page/WEAPON/TakePrimaryAmmo