Skip to content

10% off shop orders, applied at checkoutBlack Friday: 30% off until Dec 1Server templatesServer templates

RPScripts

How to Sync the FiveM Game Clock to UTC

By Luke

FiveM Real-Time Sync
On this page

This small development resource makes every connected client display the FXServer host’s UTC time. Use it only when it is the sole owner of the game clock. If your framework already manages time and weather, configure or extend that resource instead of running two clock systems.

This example requires state-awareness support for GlobalState. Stop other time/weather synchronization resources on the test instance so one controller owns the clock. It displays UTC, not the server host’s local time zone.

This GlobalState time sync targets FiveM for GTA V Legacy; check Cfx.re’s Legacy-to-Enhanced changes before running it on an Enhanced server.

Prepare the test

Check that the host clock is accurate. Back up the existing time-resource configuration and use an isolated server. Create resources/[local]/utc_clock with the three files below. The server publishes time; clients cannot set GlobalState values on the server.

1. Declare the resource

Save this as fxmanifest.lua:

fx_version 'cerulean'
game 'gta5'
server_script 'server.lua'
client_script 'client.lua'

2. Publish UTC from the server

Save this as server.lua. The leading exclamation mark in os.date selects UTC rather than the host’s local time zone:

CreateThread(function()
    while true do
        local now = os.date('!*t')
        GlobalState.tutorialUtcClock = {
            hour = now.hour, minute = now.min, second = now.sec
        }
        Wait(1000)
    end
end)

AddEventHandler('onResourceStop', function(name)
    if name == GetCurrentResourceName() then
        GlobalState.tutorialUtcClock = nil
    end
end)

3. Display the shared clock

Save this as client.lua:

CreateThread(function()
    while true do
        local clock = GlobalState.tutorialUtcClock
        if clock then
            NetworkOverrideClockTime(clock.hour, clock.minute, clock.second)
        end
        Wait(1000)
    end
end)

AddEventHandler('onResourceStop', function(name)
    if name == GetCurrentResourceName() then
        NetworkClearClockTimeOverride()
    end
end)

Start, check and stop

  1. Add ensure utc_clock to server.cfg after disabling the competing clock controller on the test server.
  2. In the server console, run refresh and ensure utc_clock. Join with two clients and compare their displayed game time with current UTC.
  3. Reconnect one client, restart the resource and repeat the comparison. Inspect both F8 and server logs.
  4. Run stop utc_clock in the server console to release this override. To restore your previous time system, remove the new ensure line and restart the original time resource or server.

Know the limits

This example follows a real 24-hour UTC day; it does not accelerate daylight or select a regional daylight-saving time zone. Network and scheduling delays mean it is not a precise wall-clock display. It does not synchronize weather.

See Cfx.re state bags and the clock override native before integrating the pattern into a larger resource.

Reference documentation

Source: lua.org

  • How to Disable Ambient Planes and Helicopters in FiveM

    How to Disable Ambient Planes and Helicopters in FiveM

    To reduce selected ambient aircraft in FiveM, create a client resource that calls SetVehicleModelIsSuppressed for an explicit list of model hashes. This targets natural spawning of those models; it is not a permission system and does not guarantee that another resource cannot create the same aircraft.

  • How to Review AI-Generated FiveM Code

    How to Review AI-Generated FiveM Code

    Use AI to explain a small piece of FiveM code or propose a narrow change, then verify the result against your exact framework source. Generated code is a draft: it can invent exports, miss dependencies and trust values that should be checked on the server.

  • FiveM Coding Languages: Lua, JavaScript and C# Compared

    FiveM Coding Languages: Lua, JavaScript and C# Compared

    FiveM officially supports Lua, JavaScript and C#. Choose the runtime that matches your framework, team skills and required libraries—not a supposed universal performance ranking. All three can call FiveM natives, handle events and expose resource APIs. The practical differences are the runtime boundary, package ecosystem, build workflow and the code already used by your dependencies.