Resource start order

Hi I have a resource that uses another resource. The weird thing is that the first resource is not working unless you restart that specific resource. I thought this probably was because the first resource got started before the second one and just wondered if there is a way to make sure two resources start in a specific order other then the order of the ensures in the cfg file

Good question with simple answer; Yes, there is a way.

Other than placing one resource above the other in the server.cfg file, you can add scripts as dependencies and this will ensure that the other script it depends on has started, before it starts up itself. This is done in the fxmanifest.lua file.

Just chuck any dependencies at the bottom like this;

dependency 'es_extended'

OR

dependencies {
    'es_extended',
    'esx_policejob'
}

Example:

fx_version 'cerulean'
games { 'gta5' }

client_script 'client.lua'
server_script 'server.lua'

dependency 'es_extended'

You can read more about it from the official FiveM Docs.

1 Like

Yeah I did this maybe the start order isn’t my problem but basically what happens is I start my server and my first resource that depends on the second one won’t work or it stops working as soon as I get to the script where I use the second script. But it works after I restart the first resource.

Or if the second resource the I need to writing the the first one is dependent on do I need to do the exact path there if they are in different folders

I forgot to add that resources that have dependencies in the fxmanifest.lua file will be stopped when you restart the dependency script. So if “script2” has “script1” as a dependency and I restart “script1”, then “script2” will be stopped and I must manually start it back up. However restarting “script2” will not effect “script1”.

And don’t have both resources saying that each other is a dependency. That doesn’t work.

Let’s make a clearer example, incase I suck at explaining it haha. Let’s say my script CarHandler has an export or event that I wish to call from a script MechanicJob. This is what it would look like.

CarHandler/fxmanifest.lua:

fx_version 'cerulean'
games { 'gta5' }

client_script 'client.lua'

export 'getClosestDoor'

MechanicJob/fxmanifest.lua:

fx_version 'cerulean'
games { 'gta5' }

client_script 'client.lua'
server_script 'server.lua'

dependency 'CarHandler'

server.cfg

ensure CarHandler
ensure MechanicJob

And now MechanicJob can call exports["CarHandler"]:getClosestDoor() and not worry about the CarHandler script not being started before it first tries to call it. But remember, if I use restart CarHandler it will automatically stop MechanicJob and I will have to run start MechanicJob after, to get it going again.

No, you just put the script name, no path.

I will check this but sounds likely this is the problem thank you so much

It worked thank you

No worries! Please mark my response above as the solution so this thread can be considered solved and others can benefit from it, if they have the same question. :spades: