[HELP] Error nil value (global 'require')

I’ve came across a weird problem. Hope that anyone can help me.

So I decided to make a job on the server but It seems like I cant connect to the DB with the script.
I’m using the following line in server/main.lua:

> require "resources/mysql-async/lib/MySQL"
> MySQL:open("127.0.0.1", "essentialmode", "root", "")

and I get this error:

Error loading script server/main.lua in resource esx_military: server/main.lua:1: attempt to call a nil value (global 'require')
stack traceback:
        server/main.lua:1: in main chunk
Failed to load script server/main.lua.

Require hasnt been used in a long time here as lua 5.3 doesn’t use if. If you would have used the search bar you would see its been said multiple times…

I’ve been serching for 2 hours now. I always serch before I make a help post.
So what do I do now then. How do I make the plugin communicate with the db?

I believe you do

server_script “@resourcename/examplefile.lua”

Not sure though.

(In your __resource.lua file)

I believe it worked!
Thanks alot!

1 Like

The full install was in the readme

Unfortunately some old tutorials have yet to be removed using the require method but you can use that method to load any external Lua files from another resource as MySQL Async shows a good example for that.

1 Like

Okay next problem.
It tells me that I have an error in my config.lua

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

description 'Military Job'

version '1.0.0'

server_scripts {
  '@es_extended/locale.lua',
  '@mysql-async/lib/MySQL.lua',
  'config.lua',
  'server/main.lua'
}

client_scripts {
  '@es_extended/locale.lua',
  '@mysql-async/lib/MySQL.lua',
  'config.lua',
  'server/main.lua'
}

files {
	'html/ui.html',
	'html/bankgothic.ttf',
	'html/pdown.ttf',
	'html/css/app.css',
	'html/scripts/mustache.min.js',
	'html/scripts/app.js',
	'html/img/keys/enter.png',
	'html/img/keys/return.png'
}

ui_page 'html/ui.html'

Error code:

Error parsing script config.lua in resource esx_military: config.lua:18: '}' expected (to close '{' at line 4) near 'Config'

Help? xD

Your not closing the config table.

1 Like

Thanks alot.
This helped. I was looking at the __resouce.lua file

To use the @, does teh resource have to be in the same folder ? Or it just needs to be one of the resources ?

Thanks

@resourcename/folderifneeded/file.lua

1 Like

Even if they are not in the same resources folder ? Example, I have a [ESX] resources folder with all my ESX resources and a [FiveMDefault] with my other resources will it work anyways ?

Thanks

@resourcename – will search for any resource called ‘resourcename’ in the ‘resources/’ folder.

1 Like

Alright thank you ! Actually I wanted to get only 1 variable so I might export it because it gives me other problems when using this method.

Do you know if it’s possible top export only one variable ?

Thanks