Attempt to index local 'hand' (a nil value)

So I did not create the addon I’m having issues with, this error just keeps popping up in my console and it is on every weapon that the creator of the addon has made. The creator isn’t responding so I turned to you guys. Here is the error:
[ERROR] lua/weapons/notmic_galil/shared.lua:92: attempt to index local ‘hand’ (a nil value)
unknown - lua/weapons/notmic_galil/shared.lua:92

Here is the code for lua/weapons/notmic_galil/shared.lua:
– Variables that are used on both client and server
SWEP.Gun = (“notmic_galil”) – must be the name of your swep but NO CAPITALS!
if (GetConVar(SWEP.Gun…"_allowed")) != nil then
if not (GetConVar(SWEP.Gun…"_allowed"):GetBool()) then SWEP.Base = “bobs_blacklisted” SWEP.PrintName = SWEP.Gun return end
end
SWEP.Category = “Not Micro’s Weapons”
SWEP.Author = “”
SWEP.Contact = “”
SWEP.Purpose = “”
SWEP.Instructions = “”
SWEP.MuzzleAttachment = “1” – Should be “1” for CSS models or “muzzle” for hl2 models
SWEP.ShellEjectAttachment = “2” – Should be “2” for CSS models or “1” for hl2 models
SWEP.PrintName = “IMI Galil” – Weapon name (Shown on HUD)
SWEP.Slot = 2 – Slot in the weapon selection menu
SWEP.SlotPos = 21 – Position in the slot
SWEP.DrawAmmo = true – Should draw the default HL2 ammo counter
SWEP.DrawWeaponInfoBox = false – Should draw the weapon info box
SWEP.BounceWeaponIcon = false – Should the weapon icon bounce?
SWEP.DrawCrosshair = true – set false if you want no crosshair
SWEP.Weight = 30 – rank relative ot other weapons. bigger is better
SWEP.AutoSwitchTo = true – Auto switch to if we pick it up
SWEP.AutoSwitchFrom = true – Auto switch from if you pick up a better weapon
SWEP.HoldType = “ar2” – how others view you carrying the weapon
– normal melee melee2 fist knife smg ar2 pistol rpg physgun grenade shotgun crossbow slam passive
– you’re mostly going to use ar2, smg, shotgun or pistol. rpg and crossbow make for good sniper rifles

SWEP.SelectiveFire = true

SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = false
SWEP.ViewModel = “models/weapons/v_notmic_galil.mdl” – Weapon view model
SWEP.WorldModel = “models/weapons/w_notmic_galil.mdl” – Weapon world model
SWEP.Base = “bobs_gun_base”
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.FiresUnderwater = false

SWEP.Primary.Sound = Sound(“weapons/galil_ins/galil_ins-1.wav”) – Script that calls the primary fire sound
SWEP.Primary.RPM = 750 – This is in Rounds Per Minute
SWEP.Primary.ClipSize = 30 – Size of a clip
SWEP.Primary.DefaultClip = 90 – Bullets you start with
SWEP.Primary.KickUp = 0.3 – Maximum up recoil (rise)
SWEP.Primary.KickDown = 0.3 – Maximum down recoil (skeet)
SWEP.Primary.KickHorizontal = 0.3 – Maximum up recoil (stock)
SWEP.Primary.Automatic = true – Automatic = true; Semi Auto = false
SWEP.Primary.Ammo = “ar2” – pistol, 357, smg1, ar2, buckshot, slam, SniperPenetratedRound, AirboatGun
– Pistol, buckshot, and slam always ricochet. Use AirboatGun for a light metal peircing shotgun pellets

SWEP.Secondary.IronFOV = 65 – How much you ‘zoom’ in. Less is more!

SWEP.data = {} --The starting firemode
SWEP.data.ironsights = 1

SWEP.Primary.NumShots = 1 – How many bullets to shoot per trigger pull
SWEP.Primary.Damage = 20 – Base damage per bullet
SWEP.Primary.Spread = .025 – Define from-the-hip accuracy 1 is terrible, .0001 is exact)
SWEP.Primary.IronAccuracy = .015 – Ironsight accuracy, should be the same for shotguns

– Enter iron sight info and bone mod info below
SWEP.IronSightsPos = Vector(-2.498, 0, 0.68)
SWEP.IronSightsAng = Vector(0, 0, 0)
SWEP.SightsPos = Vector(-2.498, 0, 0.68)
SWEP.SightsAng = Vector(0, 0, 0)
SWEP.RunSightsPos = Vector(4.159, 0, 1.039)
SWEP.RunSightsAng = Vector(-7.2, 39.7, 0)

if GetConVar(“M9KDefaultClip”) == nil then
print(“M9KDefaultClip is missing! You may have hit the lua limit!”)
else
if GetConVar(“M9KDefaultClip”):GetInt() != -1 then
SWEP.Primary.DefaultClip = SWEP.Primary.ClipSize * GetConVar(“M9KDefaultClip”):GetInt()
end
end

if GetConVar(“M9KUniqueSlots”) != nil then
if not (GetConVar(“M9KUniqueSlots”):GetBool()) then
SWEP.SlotPos = 2
end
end

function SWEP:DrawWorldModel()

local hand, offset, rotate

if not IsValid(self.Owner) then
	self:DrawModel()
	return
end

hand = self.Owner:GetAttachment(self.Owner:LookupAttachment("anim_attachment_rh"))

offset = hand.Ang:Right() * -1 + hand.Ang:Forward() * 6 + hand.Ang:Up() * 0

hand.Ang:RotateAroundAxis(hand.Ang:Right(), 10)
hand.Ang:RotateAroundAxis(hand.Ang:Forward(), 10)
hand.Ang:RotateAroundAxis(hand.Ang:Up(), 0)

self:SetRenderOrigin(hand.Pos + offset)
self:SetRenderAngles(hand.Ang)

self:DrawModel()

if (CLIENT) then
	self:SetModelScale(1,1,1)
end

end

Check if “hand” is valid before using it.

How exactly would I do this? Sorry i’m a little bit of a lua newb.

IsValid

GetAttacment will return nil or a table. You can check its validity with:


if (not hand) then return end

Yes, my mistake . if bad reading were a thing still, I’d definitely deserve it.

Though IsValid also performs a nil check so you’d still be good using it.

You wouldn’t be as alongside checking for nil, IsValid calls the IsValid method of the object, it’d return false no matter what in this case.