Inventory system not working


local ply = FindMetaTable( "Player" )
util.AddNetworkString( "database" )

function ply:ShortSteamID()

	local id = self:SteamID()
	local id = tostring( id )
	local id = string.Replace( id, "STEAM_0:0:", "" )
	local id = string.Replace( id, "STEAM_0:1:", "" )
	return id

end

local oldPrint = print
local function print( s )

	oldPrint( "database.lua " .. s )
	
end

function ply:databaseDefault()

	self:databaseSetValue( "Money", 1000 )
	self:databaseSetValue( "xp", 0 )
	self:databaseSetValue( "hunger", 0 )
	self:databaseSetValue( "thirst", 0 )
	
	local i = {}
	i["soda"] = { amount = 4 }
	i["beans"] = { amount = 4 }
	self:databaseSetValue( "inventory", i )

end

function ply:databaseNetworkedData()

	local money = self:databaseGetValue{ "money" }
	local xp = self:databaseGetValue{ "xp" }
	local hunger = self:databaseGetValue{ "hunger" }
	local thirst = self:databaseGetValue{ "thirst" }

	self:SetNWInt( "money", money )
	self:SetNWInt( "xp", xp )
	self:SetNWInt( "hunger", hunger )
	self:SetNWInt( "thirst", thirst )
	
	self:KillSilent()
	self:Spawn()
	
end

function ply:databaseFolders()

	return "server/1943rp/players/" .. self:ShortSteamID() .. "/"

end

function ply:databasePath()

	return self:databaseFolders() .. "database.txt"

end

function ply:databaseSet( tab )

	self.database = tab

end

function ply:databaseGet()
	
	return self.database
	
end

function ply:databaseCheck()
	self.database = {}
	local f = self:databaseExists()
	if f then
		self:databaseRead()
	else
		self:databaseCreate()
	end
	self:databaseSend()
	self:databaseNetworkedData()
end

function ply:databaseSend()

	net.Start( "database" )
		net.WriteTable( self:databaseGet() )
	net.Send( self )

end

function ply:databaseExists()

	local f = file.Exists(self:databasePath(), "DATA")
	return f
	
end

function ply:databaseRead()

	local str = file.Read( self:databasePath(), "DATA" )
	
	self:databaseSet( util.KeyValuesToTable( str ) )

end

function ply:databaseSave()

	local str = util.TableToKeyValues( self.database )
	local f = file.Write( self:databasePath(), str )
	
	self:databaseSend()

end

function ply:databaseCreate()

	self:databaseDefault()
	local b = file.CreateDir( self:databaseFolders() )
	self:databaseSave()

end

function ply:databaseDisconnect()

	self:databaseSave()

end

function ply:databaseSetValue( name, v )

	if not v then return end
	
	if type( v ) == "table" then
	
		if name == "inventory" then
		
			for k, b in pairs( v ) do
			
				if b.amount <= 0 then
				
					v[k] = nil
				
				end
			
			end
		
		end
		
	end
	
	local d = self:databaseGet()
	d[name] = v
	
	self:databaseSave()

end

function ply:databaseGetValue( name )

	local d = self:databaseGet()
	return d[name]

end

Getting this error:


[ERROR] gamemodes/1943rp/gamemode/player.lua:34: attempt to index a nil value
  1. GiveGamemodeItems - gamemodes/1943rp/gamemode/player.lua:34
   2. unknown - gamemodes/1943rp/gamemode/init.lua:29
    3. Spawn - [C]:-1
     4. databaseNetworkedData - gamemodes/1943rp/gamemode/database/database.lua:
48
      5. databaseCheck - gamemodes/1943rp/gamemode/database/database.lua:85
       6. unknown - gamemodes/1943rp/gamemode/init.lua:53
        7. UniqueID - [C]:-1
         8. query - addons/ulib/lua/ulib/shared/sh_ucl.lua:48
          9. echoToAdmins - addons/ulx/lua/ulx/log.lua:164
           10. fn - addons/ulx/lua/ulx/log.lua:196
            11. unknown - addons/ulib/lua/ulib/shared/hook.lua:183