Trying to make pointshop only accessible to VIP and up, getting "attempted to index global 'ply' (a nil value)"

I’m trying to set up Pointshop on my server to be only accessable by VIP+ classes (i.e. not the default “user” group). Here’s my code:


-- VIP only functions
function isVIP( ply )
	if ply:IsUserGroup('user') then return true end
end	--this is line 12 in the code
--menu stuff
function PS:ToggleMenu()
	if not ply:IsUserGroup('user') then
		if not PS.ShopMenu then
			PS.ShopMenu = vgui.Create('DPointShopMenu')
			PS.ShopMenu:SetVisible(false)
		end
		
		if PS.ShopMenu:IsVisible() then
			PS.ShopMenu:Hide()
			gui.EnableScreenClicker(false)
		else
			PS.ShopMenu:Show()
			gui.EnableScreenClicker(true)
		end
	else
		window = vgui.Create( "DFrame" )
		window:SetSize( 500, 100 )
		window:Center()
		window:SetTitle( "Error!" )
		window:SetVisible( true )
		window:SetDraggable( false )
		window:ShowCloseButton( false )
		window:MakePopup()

		button = vgui.Create( "DButton", window )
		button:SetSize( 450, 75 )
   		button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() / 2 )
   		button:SetText( "Pointshop is only available for VIPs!" )

   		button.DoClick = function() window:Close() end
	end
end

I get this error:


[ERROR] addons/pointshop-master/lua/cl_pointshop.lua:11: attempt to index local 'ply' (a nil value)
  1. isVIP - addons/pointshop-master/lua/cl_pointshop.lua:11
   2. ToggleMenu - addons/pointshop-master/lua/cl_pointshop.lua:17
    3. func - addons/pointshop-master/lua/cl_pointshop.lua:88
     4. unknown - lua/includes/modules/net.lua:31

Basically all the pointshop junk opens if the player’s usergroup isn’t “user” (I do have ULX installed and properly configured). In various pointshop tutorials, I’ve seen this method used in sh_config.lua for PS, passing the following:


PS.Config.CalculateBuyPrice = function(ply, item)
	-- 25% off for the 'donators' group
	if ply:IsUserGroup('donators') then return math.Round(item.Price * 0.75) end
	return item.Price
end

Is the issue that I’m trying to pass a check for ply as client, instead of server? I honestly can’t crack this one.

For the first one, you need to define what ‘ply’ is.
Enter this between ‘function PS:Togglemenu()’ and ‘if not ply:IsUserGroup’.
[lua] local ply = LocalPlayer() [/lua].

That should work.

No idea about the other one though.

This worked! My final code is:


function PS:ToggleMenu() 
	local ply = LocalPlayer()
	if not ply:IsUserGroup('user') then
		if not PS.ShopMenu then
			PS.ShopMenu = vgui.Create('DPointShopMenu')
			PS.ShopMenu:SetVisible(false)
		end
		
		if PS.ShopMenu:IsVisible() then
			PS.ShopMenu:Hide()
			gui.EnableScreenClicker(false)
		else
			PS.ShopMenu:Show()
			gui.EnableScreenClicker(true)
		end
	else
		window = vgui.Create( "DFrame" )
		window:SetSize( 450, 100 )
		window:Center()
		window:SetTitle( "Error!" )
		window:SetVisible( true )
		window:SetDraggable( false )
		window:ShowCloseButton( false )
		window:MakePopup()

		button = vgui.Create( "DButton", window )
		button:SetSize( 400, 60 )
   		button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )
   		button:SetText( "Pointshop is only available for VIPs!" )

   		button.DoClick = function() window:Close() end
	end
end

The other one was just some code in the sh_config.lua that I copied over, I posted it cause it was my main source.

No problem. I recommend you make this post solved so others with the same problem can easily find the answer! :slight_smile: