How to execute command through script?

Hello everyone !

I’m trying to make a script who can restart a ressource, but i don’t know the fonction to type the command
I know how make a /command but how send a restart to the server console ?

Because I a have a script doesn’t work but when I make a restart it works… It’s weird

Exemple of what I mean :

/test
=> The script “IDontWork” is restart
/teststop
=>The script “IDontWork” is stopped

3 Likes

https://runtime.fivem.net/doc/natives/?_0x561C060B

Example uses:

ExecuteCommand( "restart IDontWork" )
ExecuteCommand( "stop IDontWork" )
1 Like

I might be none of my business, but if you have a script that only works after restarting it, creating another script just to restart the first one, doesn’t sound like a good solution. You probably have a broken export, or a dependency issue, or even something loading too early on that script. Fixing the script might be the best way to go.

3 Likes

image
But when I do this, i don’t the acces to restart the ressource

I will try to find the problem to the 1st script

You need to give yourself permissions. Start, restart, and stop all require elevated privileges.

Haaa ok, but this command will be for everyone so if i gave permission to everyone can restart/stop every script (if they use F8) ?

Why would you want to do that?

Because the 1st script only work if i do a restart of it
That why but, like MrFrk say it my be a problem of loading of the 1st script

1 Like

Just add you as a server admin from server.cfg.