Reputation: 21
I am currently working on a Garry's Mod SWEP for my friends server. I have been troubleshooting for about 8 hours, when i got this strange error:
line 13: attempt to index global 'SWEP' (a nil value)
stack traceback:
t.lua:13: in main chunk
[C]: ?
not sure what it means, as i am fairly new to LUA.
Here is my whole script (also at codepad):
if SERVER then
SWEP.Weight = 30
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = true
end
if CLIENT then
SWEP.PrintName = "Bill Nye's Test Weapon"
SWEP.Slot = 4
SWEP.SlotPos = 1
end
SWEP.Base = "weapon_base" -- line 13
SWEP.Category = "Bill Nye's Admin Weapons"
SWEP.Author = "Bill Nye The Russian Spy"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModelFlip = true
SWEP.HoldType = "ar2"
SWEP.ViewModel =
{["element_name2"] = { type = "Model", model = "models/XQM/cylinderx2.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.027, 4.118, 0.518), angle = Angle(-90.025, -4.764, -0.364), size = Vector(0.167, 0.167, 0.167), color = Color(90, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name4"] = { type = "Model", model = "models/props_lab/huladoll.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(-0.89, 3.947, 1.452), angle = Angle(-86.752, -1.621, -180), size = Vector(0.273, 0.273, 0.273), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name3"] = { type = "Model", model = "models/props_phx/construct/glass/glass_plate1x1.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.017, 6.109, 2.431), angle = Angle(0, 0, 0), size = Vector(0.041, 0.041, 0.041), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 3, bodygroup = {} },
["element_name"] = { type = "Model", model = "models/sprops/misc/alphanum/alphanum_plu.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.067, 6.19, 2.417), angle = Angle(0, -1.17, 87.662), size = Vector(0.107, 0.107, 0.107), color = Color(255, 0, 0, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}}
}
SWEP.WorldModel =
{["element_name2"] = { type = "Model", model = "models/XQM/cylinderx2.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.316, 0.736, -4.292), angle = Angle(0, 0, 0), size = Vector(0.167, 0.167, 0.167), color = Color(90, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name4"] = { type = "Model", model = "models/props_lab/huladoll.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.987, 0.634, -5.249), angle = Angle(180, 17.653, 0), size = Vector(0.273, 0.273, 0.273), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
["element_name3"] = { type = "Model", model = "models/props_phx/construct/glass/glass_plate1x1.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(12.293, 0.656, -7.63), angle = Angle(88.204, 1.24, 1.22), size = Vector(0.041, 0.041, 0.041), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 3, bodygroup = {} },
["element_name"] = { type = "Model", model = "models/sprops/misc/alphanum/alphanum_plu.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(12.619, 0.646, -7.801), angle = Angle(0, 89.783, 0.244), size = Vector(0.107, 0.107, 0.107), color = Color(255, 0, 0, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}}
}
SWEP.Primary.Recoil = 0.00
SWEP.Primary.Damage = 1000
SWEP.Primary.NumShots = 1
SWEP.Primary.Spread = 0
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = 27
SWEP.Primary.DefaultClip = 100
SWEP.Primary.Ammo = "ar2"
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.1
SWEP.IronSightsPos = Vector(6.099, -13.468, 2.612)
SWEP.IronSightsAng = Vector(3.517, 0, -0)
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
function SWEP:Initialize()
self:SetWeaponHoldType(self.HoldType)
end
function SWEP:PrimaryAttack()
if (self:CanPrimaryAttack()) then
return
end
local Bullet = {}
Bullet.Num = self.Primary.NumShots
Bullet.Src = self.Owner:GetShootPos ()
Bullet.Dir = self.Owner:GetAimVector ()
Bullet.Spread = Vector(self.Primary.Spread, self.Primary.Spread,0)
Bullet.Tracer = 0
Bullet.Damage = self.Primary.Damage
Bullet.AmmoType = self.Primary.Ammo
self:ShootEffects()
self:FireBullets(Bullet)
self:EmitSound ("Weapon_IRifle.Single")
self:TakePrimaryAmmo ( 1 )
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
end
function SWEP:SecondaryAttack()
return false
end
Upvotes: 1
Views: 628
Reputation: 124
It means: in your t.lua file on line 13 you point to SWEP value, which is a null value.
Did you call: SWEP:initialize()
?
function SWEP:Initialize()
self:SetWeaponHoldType(self.HoldType)
end
check if your value is "local" or if your SWEP value has been initialized. also check if you remove it before like this: SWEP = nil or not.
Upvotes: 1