attempt to call global 'LocalPlayer' error

My error is:

[ERROR] lua/tttmenu_new.lua:3: attempt to call global ‘LocalPlayer’ (a nil value)

  1. unknown - lua/tttmenu_new.lua:3
  2. unknown - lua/includes/modules/concommand.lua:69

My code is


function TTTMenu()

	local ply = LocalPlayer()

	local DPanel = vgui.Create( "DFrame" )
	DPanel:SetPos( 10, 30 )
	DPanel:SetSize( 200, 200 )
	DPanel:SetTitle( "TTT Admin Menu Alpha!" )
	DPanel:SetVisible( true )
	DPanel:SetDraggable( true )
	DPanel:ShowCloseButton( true )
	DPanel:MakePopup()

	local DComboBox = vgui.Create( "DComboBox", DPanel )
	local selected
	DComboBox:SetPos( 5, 5 )
	DComboBox:SetSize( 100, 20 )
	DComboBox:SetValue( "options" )
	DComboBox:AddChoice( "Say" )
	DComboBox:AddChoice( "Kill" )
	DComboBox:AddChoice( "option C" )
	DComboBox.OnSelect = function( panel, index, value )
		selected = value
	print( value .." was selected!" )

	local commands = {
	"say hi",
	"kill",
	"kill"
}

	local DButton = vgui.Create( "DButton", DPanel )
	DButton:SetSize( 160, 40 )
	DButton:SetText( "test" )
	DButton:SetPos( 20, 30 )
	DButton.DoClick = function()
		RunConsoleCommand(commands[selected])
	end


end
end
concommand.Add( "tttadmin", TTTMenu)


You are probably calling this serverside instead of clientside, which doesnt work.

You aren’t even using ply? And remember that this has to go clientside, and not serverside!

I’d refrain from making admin-related stuff if you’re inexperienced. It would be easy to make a mistake that would cost you your server’s security’s integrity.

How would I call it clientside, I don’t have the luascript on the server

The code is unfinished, put I’m probably going to remove that line

I’m not going to be doing this on a public server

This is a client script ran from your own client? Then run it as lua_openscript_cl and not lua_openscript

I was always wondering the difference with lua_openscript_cl and lua_openscript, thanks!

No problem, the _cl stands for client. Basically anything you run from your client gets executed with that. lua_openscript is more for servers to be executed from the live console

Nobody told him about sv_allowcslua. Might want to turn that off if you’re on a dedi.