Automatic command script thing

Where or how can i get a script that AUTOMATICALLY does a specific command every hour for instance.

You can easy create this script by your own, just get the time and if its +1 hours execute the command or create a timer than execute the command. You can use the natives.

https://docs.fivem.net/docs/scripting-manual/runtimes/lua/

People, give real answears or do not reply if you do not want to help OP.

CreateThread(function()
    local hours = 1
    while true do
        Wait((600000*6)*hours)
        ExecuteCommand('command_name')
    end
end)

This is the whole code, Put it in either server or client script.

4 Likes

how about something like this but only does it when the script is started. basically to run a command on server start/ restart

Literally use RunCommand(*) anywhere in the script, it’ll run when the resource is started by the server

how would i set it up in my script. i have a command /spawnallcars that i want to run on server start and restart.

That’s a little different, you’d be better off triggering whatever functionality that command has separately. Get a server script to trigger it when there’s at least one player on the server, should be super short

kinda a noob to the scripting. the code above worked but i didnt like the fact it was every so often rather than on restart and it was causing dups of owned cars to spawn. its for my garage/ vehicle script it has built in vehicle persistance but requires the command to spawn them in at the last location it was parked

Is the command client-specific (per each client) or can be ran once, and any player joining later will see the effects? Verify that for sure.

server sided command once ran the will stay out till restart then the command needs to be ran again

Yeah, some simple logic then, put it in any server script outside of any loops or if statements and it should be executed