Attempt to index global 'lp' (a nil value)

My last thread didn’t solve my problem, so here we go again.


lp = nil

function SWEP:OwnerChanged()
	if CLIENT then
		if  IsValid(LocalPlayer()) then
			lp = LocalPlayer()
			print (lp)
		end
	end
end

function SWEP:OnDrop()
	self:Remove()
end

function SWEP:OnRemove()
	local tiers =  {none=1,
				bronze=2,
				silver=3,
				gold=4,
				ostrich=5}
		local donorlevel = lp:GetUserGroup() -- ERROR ON THIS LINE
		local dlevel = 1
		for i,v in pairs(tiers) do		
			if donorlevel:match(i) then
				dlevel = v
				break
			end
		end	
		print(dlevel)
		if dlevel > 2 then
			if SERVER then
				lp:Give("weapon_ttt_drawbar")
			end
		end
end

I get the error:
Attempt to index global ‘lp’ (a nil value)
as said in the title,
for the line I commented on.
Please help!
Thanks

[editline]22nd February 2015[/editline]

I am only getting the error server-side, client-side it is not having a problem, in fact the rest of the function is being returned correctly

Because lp only exists clientside as you are only setting it clientside. Tbh, I’m not sure why you need lp when you can use self.Owner.

Updated the code, but new error


function SWEP:OnDrop()
	self:Remove()
end

function SWEP:OnRemove()
	local tiers =  {none=1,
				bronze=2,
				silver=3,
				gold=4,
				ostrich=5}
	local donorlevel = self.Owner:GetUserGroup() --attempted to call GetUserGroup (a nil value)
	local dlevel = 1
	for i,v in pairs(tiers) do		
		if donorlevel:match(i) then
			dlevel = v
			break
		end
	end	
	print(dlevel)
	if dlevel > 2 then
		if SERVER then
			lp:Give("weapon_ttt_drawbar")
		end
	end
end

For the line I commented on, I get the error attempted to call GetUserGroup (a nil value)
The error is only serverside

Unless you created the function GetUserGroup use



self.Owner:GetNWString("usergroup", "user")


Should work though since it’s a GMod function:

I’d add an IsValid check for self.Owner.