!ply:IsSuperAdmin() nil value error?

Alright, so before I posted this, JUST FOR EVERYONE TO KNOW, I did search the problem, none fixed it.

Anyways, so i’m trying to get this to work for my test gamemode.


team4:SetParent(changeteam)
	team4:SetText("Republic 501st")
	team4:SetPos(150, 70)
	team4:SetSize(150, 50)
	team4.DoClick = function(ply)
		if !ply:IsSuperAdmin() or !ply:IsAdmin() then RunConsoleCommand("sw_setteam4")
		end
	end
end

How ever, all I get from it is:



[ERROR] gamemodes/swcw/gamemode/cl_init.lua:69: attempt to call method 'IsSuperAdmin' (a nil value)
  1. DoClick - gamemodes/swcw/gamemode/cl_init.lua:69
   2. unknown - lua/vgui/dlabel.lua:206



How does one fix this problem?

DoClick does not give you any “ply” object as you have defined it. I’m not sure about your intents but since this is clientside you might want to use LocalPlayer() instead of ply, like “LocalPlayer():IsSuperAdm…”

I did, I called


local ply = LocalPlayer()

Yeah but doclick sends its own panel as the first argument, so inside that function ply will actually be the button itself and not the localplayer. To fix this just remove ply from the arguments.

Your ply variable is overridden inside that function because you have put ply as function argument.

Well, I did something.


team4.DoClick = function()
		if !ply:IsSuperAdmin() or !ply:IsAdmin() then RunConsoleCommand("sw_setteam4")
		end
	end
end

Posted this before I refreshed. >:(

Now, when I clicky clicky, it doesn’t appear to make lua errors, however, it DOESN’T set my team. I’ve already got all the con commands setup.

[editline]8th May 2014[/editline]

Fixed that part, but when I remove access from superadmin to user, I can still join that team…

[editline]8th May 2014[/editline]

NVM, fixed it, thanks for the help :slight_smile:

I’m not so sure your logic is correct behind that if statement. I assume you want it to be superadmin only, if then, you’d only want “if issuperadmin then … end”

Also, assuming you’ve not remade them, IsAdmin will return true when you’re a superadmin so only need to check that.

Forgot to hit solved, thanks guys for your help.

If anyone is looking to solve this problem, PM or add me on steam. :slight_smile: (I’d rather have you PM me)