(Lua) [ERROR] bad argument #1 to 'JSONToTable'

Hello I made this addon and it works almost perfectly in single player, but now it will not work on my server Please help, Thanks :smiley:


[ERROR] addons/excuse/lua/autorun/server/aa_server.lua:53: bad argument #1 to 'JSONToTable' (string expected, got nil)

Can you post code?


if not App then App = {} end
App.Responses = {}
App.Responses.Textbased = {}
App.Responses.Multichoice = {}

for k,v in pairs(App.TextQuestions) do
	App.Responses.Textbased[k] = ""
end
for key, question in pairs(App.MultiChoiceQuestions) do
	App.Responses.Multichoice[key] = ""
end



local BlurMaterial = Material( "pp/blurscreen" )

function Blurpanel( panel, layers, density, alpha )

	-- Thanks Chessnut!

	local x, y = panel:LocalToScreen(0, 0)

	surface.SetDrawColor( 255, 255, 255, alpha )
	surface.SetMaterial( BlurMaterial )

	for i = 1, 3 do
		BlurMaterial:SetFloat( "$blur", ( i / layers ) * density )
		BlurMaterial:Recompute()

		render.UpdateScreenEffectTexture()
		surface.DrawTexturedRect( -x, -y, ScrW(), ScrH() )
	end
end



surface.CreateFont( "HeaderTitles", {
	font = "Arial",
	size = ScreenScale(14),
	weight = 500,
} )
surface.CreateFont( "HeaderTitles1", {
	font = "Arial",
	size = ScreenScale(10),
	weight = 500,
} )

net.Receive("App_apply",function()

	local Frame = vgui.Create( "DFrame" )
	Frame:SetPos( 100, 100 )
	Frame:SetSize( ScrW() / 1.7, 230 )
	Frame:Center()
	Frame:SetTitle( "" )
	Frame:SetDraggable( false )
	Frame:MakePopup()
	
	Frame.Paint = function( pnl,w,h)
		Blurpanel( pnl, 10, 20, 255 )
		draw.RoundedBox(0,0,0,w,h,Color(149, 165, 166, 105))
		draw.RoundedBox(0,0,0,w,23,Color(41, 128, 185, 155))
	end
		
	local Scroll = vgui.Create( "DScrollPanel", Frame ) 
	Scroll:SetSize( Frame:GetWide() - 10, Frame:GetTall() - 35 )
	Scroll:SetPos( 5, 30 )

	local List	= vgui.Create( "DIconLayout", Scroll )
	List:SetSize( Scroll:GetWide() , Scroll:GetTall() )
	List:SetPos( 0, 0 )
	List:SetSpaceY( 5 ) 
	List:SetSpaceX( 5 ) 
	
	local TextHeader = List:Add("DPanel")
	TextHeader:SetSize(List:GetWide() - 5, 64)
	TextHeader.Paint = function(pnl,w,h)
		draw.RoundedBox(0,0,0,w,h,Color(0,0,0,100))
		draw.SimpleText( "Submit an App Here", "HeaderTitles", w/2, 5, Color(255,255,255), TEXT_ALIGN_CENTER )
		draw.SimpleText( "", "HeaderTitles1", w/2, 35, Color(255,255,255), TEXT_ALIGN_CENTER )
	end
	
	for k,v in pairs(E.TextQuestions) do
	
		local ListItem = List:Add( "DPanel" ) 
		ListItem:SetSize( List:GetWide() - 10, 64 )
		
		ListItem.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,h-3,w,3,Color(0,0,0,100))
			--draw.SimpleText( "Question ".. k .. " - " .. v.Question  , "HeaderTitles1", 5, 0, Color(255,255,255), TEXT_ALIGN_LEFT )
		end
		
		local TextEntry = vgui.Create( "DTextEntry", ListItem)
		TextEntry:SetPos( 5, 20 )
		TextEntry:SetSize( ListItem:GetWide() - 10, 32 )
		TextEntry:SetText( "Enter Your Response Here!" )
		TextEntry.OnTextChanged = function( self )
			E.Responses.Textbased[k] = self:GetValue()
		end
		
		TextEntry.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,0,w,h,Color(41, 128, 185,105))
			pnl:DrawTextEntryText(Color(255,255,255), pnl.m_colHighlight, pnl.m_colCursor )
			surface.SetDrawColor( Color(0,0,0,155 ) )
			surface.DrawOutlinedRect( 0, 0, w,h )			
		end
		
	end
		
	for key, question in pairs(App.MultiChoiceQuestions) do
	
		local ListItem = List:Add( "DPanel" ) 
		ListItem:SetSize( List:GetWide() / 2 - 10, 48 )
		
		ListItem.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,h-3,w,3,Color(0,0,0,100))
			--draw.SimpleText( "Question ".. key .. " - " .. question.Question  , "HeaderTitles1", 5, 0, Color(255,255,255), TEXT_ALIGN_LEFT )
		end
		
		local SelectResponse = vgui.Create( "DComboBox",ListItem )
		SelectResponse:SetPos( 5, 20 )
		SelectResponse:SetSize( 1050, 20 )
		SelectResponse:SetValue( "Select A Response" )
		SelectResponse:SetTextColor(Color(255,255,255))
		
		SelectResponse.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,0,w,h,Color(0,0,0,100))
		end
		
		for key1,response in pairs(question.Responses) do
			SelectResponse:AddChoice(response)
		end
		
		SelectResponse.OnSelect = function( panel, index, value )
			App.Responses.Multichoice[key] = value
		end
		
	end
	
	local ButtonHolder = List:Add( "DPanel" ) 
	ButtonHolder:SetSize( List:GetWide() - 10, 48 )
	ButtonHolder.Paint = function() end
	
	local SendApplication = vgui.Create( "DButton",ButtonHolder )
	SendApplication:SetPos( 5, 5 )
	SendApplication:SetText( "Send My App!" )
	SendApplication:SetSize( ButtonHolder:GetWide()  / 2 - 10 , 32 )
	SendApplication.DoClick = function()		
		Derma_Query("Do you really want to submit your App?","Submit App","Yes",function() E.SendApplication() Frame:Remove() end,"No",function() end)	
	end
	
	local CancelApp = vgui.Create( "DButton",ButtonHolder )
	CancelApp:SetPos( ButtonHolder:GetWide() / 2, 5 )
	CancelApp:SetText( "Cancel My App." )
	CancelApp:SetSize( ButtonHolder:GetWide()  / 2 - 10 , 32 )
	CancelApp.DoClick = function()
		Frame:Close()
	end

end)

function App.SendApplication()

	net.Start("App_apply")
		net.WriteTable(E.Responses.Textbased)
		net.WriteTable(E.Responses.Multichoice)
	net.SendToServer()
	
end

net.Receive("App_viewall",function()

	local Index = net.ReadTable()

	local Frame = vgui.Create( "DFrame" )
	Frame:SetPos( 100, 100 )
	Frame:SetSize( ScrW() / 2, ScrH() / 2.5 )
	Frame:Center()
	Frame:SetTitle( "View an App" )
	Frame:SetDraggable( false )
	Frame:MakePopup()
	
	Frame.Paint = function( pnl,w,h)
		Blurpanel( pnl, 10, 20, 255 )
		draw.RoundedBox(0,0,0,w,h,Color(149, 165, 166, 105))
		draw.RoundedBox(0,0,0,w,23,Color(41, 128, 185, 155))
	end

	local Scroll = vgui.Create( "DScrollPanel", Frame ) 
	Scroll:SetSize( Frame:GetWide() - 10, Frame:GetTall() - 35 )
	Scroll:SetPos( 5, 30 )

	local List	= vgui.Create( "DIconLayout", Scroll )
	List:SetSize( Scroll:GetWide() , Scroll:GetTall() )
	List:SetPos( 0, 0 )
	List:SetSpaceY( 5 ) 
	List:SetSpaceX( 5 ) 
	
	for k,v in pairs(Index) do
	
		local ListItem = List:Add( "DPanel" ) 
		ListItem:SetSize( List:GetWide() - 10, 54 )
		
		ListItem.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,h-3,w,3,Color(0,0,0,100))
			draw.SimpleText( "App ".. k .. " - SteamID: " .. v , "HeaderTitles1", 5, 0, Color(255,255,255), TEXT_ALIGN_LEFT )
		end
		
		local View = vgui.Create("DButton", ListItem )
		View:SetPos( 0, 27)
		View:SetSize( ListItem:GetWide() / 3 - 15, 22 )
		View:SetText("View Excuse")
		View.DoClick = function( self )
			net.Start("App_viewapps")
			net.WriteString(v)
			net.SendToServer()
		end

		local Accept = vgui.Create("DButton", ListItem )
		Accept:SetPos( ListItem:GetWide() / 3, 27)
		Accept:SetSize( ListItem:GetWide() / 3 - 15, 22 )
		Accept:SetText("Accept This Excuse")		
		Accept.DoClick = function()
			net.Start("App_accept")
			net.WriteString( v )
			net.SendToServer()
			
			Frame:Close()
		end

		local Decline = vgui.Create("DButton", ListItem )
		Decline:SetPos( ListItem:GetWide() / 1.5, 27)
		Decline:SetSize( ListItem:GetWide() / 3 - 15, 22 )
		Decline:SetText("Decline This Excuse")			
		Decline.DoClick = function()
			net.Start("App_decline")
			net.WriteString( v )
			net.SendToServer()
			
			Frame:Close()
			
		end		
		
	end

end)

net.Receive("App_viewapps",function()
	
	local App = net.ReadTable()
	local SteamID = net.ReadString()

	local Frame = vgui.Create( "DFrame" )
	Frame:SetPos( 100, 100 )
	Frame:SetSize( ScrW() / 1.7, 150 )
	Frame:Center()
	Frame:SetTitle( "" )
	Frame:SetDraggable( false )
	Frame:MakePopup()
	
	Frame.Paint = function( pnl,w,h)
		Blurpanel( pnl, 10, 20, 255 )
		draw.RoundedBox(0,0,0,w,h,Color(149, 165, 166, 105))
		draw.RoundedBox(0,0,0,w,23,Color(41, 128, 185, 155))
	end
		
	local Scroll = vgui.Create( "DScrollPanel", Frame ) 
	Scroll:SetSize( Frame:GetWide() - 10, Frame:GetTall() - 35 )
	Scroll:SetPos( 5, 30 )

	local List	= vgui.Create( "DIconLayout", Scroll )
	List:SetSize( Scroll:GetWide() , Scroll:GetTall() )
	List:SetPos( 0, 0 )
	List:SetSpaceY( 5 ) 
	List:SetSpaceX( 5 ) 
	
	for k,v in pairs(App.TextQuestions) do
	
		local ListItem = List:Add( "DPanel" ) 
		ListItem:SetSize( List:GetWide() - 10, 64 )
		
		ListItem.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,h-3,w,3,Color(0,0,0,100))
			draw.SimpleText( "Question ".. k .. " - " .. v.Question  , "HeaderTitles1", 5, 0, Color(255,255,255), TEXT_ALIGN_LEFT )
		end
		
		local TextEntry = vgui.Create( "DTextEntry", ListItem)
		TextEntry:SetPos( 5, 20 )
		TextEntry:SetSize( ListItem:GetWide() - 10, 32 )
		TextEntry:SetText( App.Text[k] or "Question Has No Response!" )
		TextEntry:SetDisabled( true )
		TextEntry.OnTextChanged = function(self)
			TextEntry:SetText( App.Text[k] )
		end
		
		TextEntry.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,0,w,h,Color(41, 128, 185,105))
			pnl:DrawTextEntryText(Color(255,255,255), pnl.m_colHighlight, pnl.m_colCursor )
			surface.SetDrawColor( Color(0,0,0,155 ) )
			surface.DrawOutlinedRect( 0, 0, w,h )			
		end
		
	end
		
	for key, question in pairs(E.MultiChoiceQuestions) do
	
		local ListItem = List:Add( "DPanel" ) 
		ListItem:SetSize( List:GetWide() / 2 - 10, 48 )
		
		ListItem.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,h-3,w,3,Color(0,0,0,100))
			--draw.SimpleText( "Question ".. key .. " - " .. question.Question  , "HeaderTitles1", 5, 0, Color(255,255,255), TEXT_ALIGN_LEFT )
		end
		
		local SelectResponse = vgui.Create( "DComboBox",ListItem )
		SelectResponse:SetPos( 5, 20 )
		SelectResponse:SetSize( 1050, 20 )
		SelectResponse:SetValue( App.Multi[key] or "ERROR" )
		SelectResponse:SetTextColor(Color(255,255,255))
		
		SelectResponse.Paint = function(pnl,w,h)
			draw.RoundedBox(0,0,0,w,h,Color(0,0,0,100))
		end
		
		
		SelectResponse.OnSelect = function( panel, index, value )
			SelectResponse:SetValue( App.Multi[key] )
		end
		
	end

end)

net.Receive("App_accepted",function()

	local Accepted = net.ReadTable()

	local Frame = vgui.Create( "DFrame" )
	Frame:SetPos( 100, 100 )
	Frame:SetSize( ScrW() / 2, ScrH() / 2.5 )
	Frame:Center()
	Frame:SetTitle( "Accepted Apps" )
	Frame:SetDraggable( false )
	Frame:MakePopup()
	
	Frame.Paint = function( pnl,w,h)
		Blurpanel( pnl, 10, 20, 255 )
		draw.RoundedBox(0,0,0,w,h,Color(149, 165, 166, 105))
		draw.RoundedBox(0,0,0,w,23,Color(41, 128, 185, 155))
	end

	local AppList = vgui.Create( "DListView", Frame )
	AppList:SetPos(0,0)
	AppList:Dock( 1 )
	AppList:DockMargin( 4, 0, 0, 0 )
	AppList:SetMultiSelect( false )
	AppList:AddColumn( "SteamID" )

	for k,v in pairs(Accepted) do
		AppList:AddLine( v )
	end

end)


The error is serverside and you posted clientside code.

Sorry I copied the wrong .lua file here you go.




include("autorun/aa_config.lua")


App.Applications = {}
App.Accepted = {}

local Meta = FindMetaTable("Player");

util.AddNetworkString("App_apply") -- Used to open the menu and receive the application.
util.AddNetworkString("App_viewapps") --
util.AddNetworkString("App_viewall") --
util.AddNetworkString("App_accept") --
util.AddNetworkString("App_decline") --
util.AddNetworkString("App_accepted") --



hook.Add("PlayerInitialSpawn","App:SetBlank",function(ply)

end)


net.Receive("App_apply",function(len,ply)	
	App.Applications[ply:SteamID()] = {["Text"] = {},["Multi"] = {}}
	App.Applications[ply:SteamID()] = {["Text"] = net.ReadTable(), ["Multi"] = net.ReadTable()}
	App.SaveApplications()
end)

function App.CoreDatabase()

    if (not file.IsDir("applications", "DATA")) then
        file.CreateDir("applications")
    end
	
	App.LoadApplications()
	
end

function Meta:App_Can()
	return App.Usergroups[ self:GetUserGroup() ]
end

function App.LoadApplications()

	local Apps = file.Read( "applications.txt", "DATA" )
	Apps = util.JSONToTable( Apps )
	
	App.Applications = Apps
	
	local Acc = file.Read( "accepted.txt", "DATA" )
	Acc = util.JSONToTable( Acc )
	
	App.Accepted = Acc	

end

function App.SaveApplications()

	file.Write("applications.txt", util.TableToJSON(App.Applications))
	file.Write("accepted.txt", util.TableToJSON(App.Accepted))

end

function App.RemoveApp(strSteamID)
	App.Applications[strSteamID] = nil
	App.SaveApplications()
end

hook.Add("InitPostEntity","App:DoDatabase",function()
	App.CoreDatabase()
end)

function App.RequestApp( strSteamID )
	return App.Applications[strSteamID] or {}
end


net.Receive("App_viewapps",function(len,ply)

	if( ply:App_Can() ) then

		local SteamID = net.ReadString()
		
		if( App.Applications[SteamID] ) then	
			net.Start("App_viewapps")
				net.WriteTable(App.Applications[SteamID])
				net.WriteString( SteamID )
			net.Send(ply)
		else
			ply:ChatPrint("App Not Found, Retry now.")
			App.LoadApplications()		
		end
	
	end
end)

net.Receive("App_accept",function(l,ply)

	local SteamID = net.ReadString()
	
	if( ply:App_Can() ) then
	
		local App = App.Applications[SteamID]
		App.Accepted[SteamID] = {}
		table.insert( App.Accepted[SteamID], App )
		App.RemoveApp(SteamID)
		
		if( App.AutoRank ) then
			RunConsoleCommand("ulx","adduserid",SteamID,App.RankDefualt )
		end
		App.SaveApplications()
	
	end
end)


net.Receive("App_decline",function(l,ply)
	if( ply:App_Can() ) then
	
		local SteamID = net.ReadString()
		App.RemoveApp(SteamID)
	
	end

end)

hook.Add( "PlayerSay", "AA:ChatCommands", function( ply, text, team )

	if ( string.sub( text, 1, string.len(App.Apply) ) == App.Apply ) then
		net.Start("App_apply")
		net.Send(ply)
		return false
	end
	
	if ( string.sub( text, 1, string.len(App.View) ) == App.View ) then
		if( ply:App_Can() ) then
			ply:Applications()
		end
		
		return false
		
	end	
	
		if ( string.sub( text, 1, string.len(App.ViewAcc) ) == App.ViewAcc ) then
		if( ply:App_Can() ) then
			ply:AcceptedApps()
		end
		
		return false
		
	end	
	
end )

function Meta:AcceptedApps()

	local Indexs = {}
	
	for k,v in pairs( App.Accepted ) do
		table.insert( Indexs, k )
	end
	
	net.Start("App_accepted")
	net.WriteTable( Indexs )
	net.Send( self )

end

function Meta:Applications()

	local Index = {}

	for k,v in pairs( App.Applications ) do
		table.insert( Index, k )
	end
	
	net.Start("App_viewall")
		net.WriteTable(Index or {})
	net.Send(self)

end


In your App.LoadApplications function, file.Read returns nil if the file isn’t found and util.JSONToTable only accepts a string, which causes the error. Only call util.JSONToTable if the value file.Read returns isn’t nil OR make sure the applications.txt and accepted.txt are created beforehand.

Printing the value at various places should show why/when it’s nil.

Basically missing a default value for the table.

Okay I’ll try this when I get a chance thanks for your help, I’ll respond if I need anymore.