{"id":158437,"date":"2024-09-26T14:01:24","date_gmt":"2024-09-26T12:01:24","guid":{"rendered":"https:\/\/hifivem.com\/?p=158437"},"modified":"2025-12-23T16:37:05","modified_gmt":"2025-12-23T15:37:05","slug":"fivem-real-time-sync","status":"publish","type":"post","link":"https:\/\/fivemx.com\/nl\/fivem-real-time-sync\/","title":{"rendered":"FiveM Real-Time Sync &#8211; Free FiveM Mods"},"content":{"rendered":"<p class=\"wp-block-paragraph\">This tutorial will guide you through creating a FiveM script that synchronizes the in-game clock with real-world time. This ensures that the game environment reflects the actual time, enhancing realism for players.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ll cover both server-side and client-side scripting, adding functionality to start and stop the synchronization, and setting up the resource for your FiveM server.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Inhoudsopgave<\/h2><nav><ul><li><a href=\"#prerequisites\">Voorwaarden<\/a><\/li><li><a href=\"#setting-up-the-resource-folder\">Setting Up the Resource Folder<\/a><\/li><li><a href=\"#creating-the-server-side-script-server-lua\">Creating the Server-Side Script (server.lua)<\/a><\/li><li><a href=\"#creating-the-client-side-script-client-lua\">Creating the Client-Side Script (client.lua)<\/a><\/li><li><a href=\"#adding-a-stop-functionality\">Adding a Stop Functionality<\/a><\/li><li><a href=\"#creating-the-resource-manifest-fxmanifest-lua\">Creating the Resource Manifest (fxmanifest.lua)<\/a><\/li><li><a href=\"#starting-the-resource-on-your-server\">Starting the Resource on Your Server<\/a><\/li><li><a href=\"#full-resource-download\">Full Resource Download<\/a><ul><li><a href=\"#1-server-lua\">1. server.lua<\/a><\/li><li><a href=\"#2-client-lua\">2. client.lua<\/a><\/li><li><a href=\"#3-fxmanifest-lua\">3. fxmanifest.lua<\/a><\/li><\/ul><\/li><li><a href=\"#conclusion\">Full Script<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prerequisites\">Voorwaarden<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before you begin, ensure you have the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>FiveM Server Access<\/strong>: You need administrative access to your <a href=\"https:\/\/fivemx.com\/nl\/converting-fivem-scripts\/\" title=\"Converting FiveM Scripts &#8211; ESX, QBCore, QBOX (Framework Guide)\"  data-wpil-monitor-id=\"1661\">FiveM server to add scripts<\/a>.<\/li>\n\n\n\n<li><strong>Basic Knowledge of Lua<\/strong>: Familiarity with Lua scripting will help you understand and customize the script.<\/li>\n\n\n\n<li><strong>Text Editor<\/strong>: Software like Visual Studio Code, Sublime Text, or Notepad++ for editing script files.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"setting-up-the-resource-folder\">Setting Up the Resource Folder<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Navigate to Your Resources Directory<\/strong>:Locate the <code>resources<\/code> folder in your FiveM server directory. This is typically found at:bashCode kopieren<code>your-fivem-server-folder\/resources\/<\/code><\/li>\n\n\n\n<li><strong>Create a New Resource Folder<\/strong>:Inside the <code>resources<\/code> folder, create a new folder named <code>realtime<\/code>.bashCode kopieren<code>your-fivem-server-folder\/resources\/realtime\/<\/code><\/li>\n\n\n\n<li><strong>Navigeer naar de <code>realtime<\/code> Folder<\/strong>:This folder will contain all the necessary scripts and configuration files for the real-time synchronization.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-the-server-side-script-server-lua\">Creating the Server-Side Script (<code>server.lua<\/code>)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Cre\u00ebren <code>server.lua<\/code><\/strong>:Inside the <code>realtime<\/code> folder, create a new file named <code>server.lua<\/code>.<\/li>\n\n\n\n<li><strong>Add the Following Code to <code>server.lua<\/code><\/strong>:luaCode kopieren<code>RegisterNetEvent(\"realtime:event\") AddEventHandler(\"realtime:event\", function() local hour = tonumber(os.date(\"%H\")) local minute = tonumber(os.date(\"%M\")) local second = tonumber(os.date(\"%S\")) TriggerClientEvent(\"realtime:event\", source, hour, minute, second) end) <\/code><strong>Explanation<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>RegisterNetEvent<\/strong>: Registers a network event named <code>realtime:event<\/code>.<\/li>\n\n\n\n<li><strong>AddEventHandler<\/strong>: Defines what happens when the <code>realtime:event<\/code> is triggered.<\/li>\n\n\n\n<li><strong>os.date<\/strong>: Retrieves the current system time (hour, minute, second).<\/li>\n\n\n\n<li><strong>TriggerClientEvent<\/strong>: Sends the time data to the client that triggered the event.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-the-client-side-script-client-lua\">Creating the Client-Side Script (<code>client.lua<\/code>)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Cre\u00ebren <code>client.lua<\/code><\/strong>:Inside the <code>realtime<\/code> folder, create a new file named <code>client.lua<\/code>.<\/li>\n\n\n\n<li><strong>Add the Following Code to <code>client.lua<\/code><\/strong>:luaCode kopieren<code>-- Set the duration of one in-game minute in milliseconds SetMillisecondsPerGameMinute(60000) -- 60,000 ms = 1 real-world minute RegisterNetEvent(\"realtime:event\") AddEventHandler(\"realtime:event\", function(hour, minute, second) NetworkOverrideClockTime(hour, minute, second) end) -- Trigger the server event to initiate synchronization TriggerServerEvent(\"realtime:event\") <\/code><strong>Explanation<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>SetMillisecondsPerGameMinute<\/strong>: Defines how long an in-game minute lasts. Setting it to <code>60000<\/code> makes 1 in-game minute equal to 1 real-world minute.<\/li>\n\n\n\n<li><strong>RegisterNetEvent &amp; AddEventHandler<\/strong>: Listens for the <code>realtime:event<\/code> from the server and updates the in-game clock accordingly.<\/li>\n\n\n\n<li><strong>NetworkOverrideClockTime<\/strong>: Overrides the in-game clock to match the real-world time received from the server.<\/li>\n\n\n\n<li><strong>TriggerServerEvent<\/strong>: Initiates the synchronization by triggering the server event.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"adding-a-stop-functionality\">Adding a Stop Functionality<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To allow toggling the real-time synchronization on and off, we&#8217;ll add functions to start and stop the synchronization.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Update <code>client.lua<\/code> with Stop Functionality<\/strong>:luaCode kopieren<code>local syncActive = true local syncThread = nil -- Function to start synchronization function StartRealTimeSync() if not syncActive then syncActive = true syncThread = CreateThread(function() while syncActive do TriggerServerEvent(\"realtime:event\") Wait(60000) -- Wait for 1 minute before next sync end end) end end -- Function to stop synchronization function StopRealTimeSync() if syncActive then syncActive = false if syncThread then -- In Lua, there's no direct way to kill a thread. -- Using a flag to exit the loop effectively stops the thread. syncThread = nil end end end RegisterNetEvent(\"realtime:event\") AddEventHandler(\"realtime:event\", function(hour, minute, second) if syncActive then NetworkOverrideClockTime(hour, minute, second) end end) -- Start synchronization on resource start StartRealTimeSync() -- Example: Command to toggle synchronization RegisterCommand(\"toggleTimeSync\", function() if syncActive then StopRealTimeSync() print(\"Real-time synchronization stopped.\") else StartRealTimeSync() print(\"Real-time synchronization started.\") end end, false) <\/code><strong>Explanation<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>syncActive<\/strong>: A flag to determine if synchronization is active.<\/li>\n\n\n\n<li><strong>StartRealTimeSync<\/strong>: Initiates a loop that requests time updates from the server every minute.<\/li>\n\n\n\n<li><strong>StopRealTimeSync<\/strong>: Stops the synchronization by setting the flag to false.<\/li>\n\n\n\n<li><strong>RegisterCommand<\/strong>: Adds a command (<code>\/toggleTimeSync<\/code>) that players can use to toggle synchronization on or off.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-the-resource-manifest-fxmanifest-lua\">Creating the Resource Manifest (<code>fxmanifest.lua<\/code>)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Every FiveM resource requires a manifest file that defines its metadata and dependencies.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Cre\u00ebren <code>fxmanifest.lua<\/code><\/strong>:Inside the <code>realtime<\/code> folder, create a new file named <code>fxmanifest.lua<\/code>.<\/li>\n\n\n\n<li><strong>Add the Following Code to <code>fxmanifest.lua<\/code><\/strong>: <code>fx_version 'cerulean' game 'gta5' author 'YourName' description 'Real-Time Synchronization Script for FiveM' version '1.0.0' server_script 'server.lua' client_script 'client.lua'<\/code><\/li>\n\n\n\n<li><strong>Explanation<\/strong>:\n<ul class=\"wp-block-list\">\n<li><strong>fx_version<\/strong>: Specifies the version of the FiveM manifest. <code>cerulean<\/code> is the latest as of writing.<\/li>\n\n\n\n<li><strong>game<\/strong>: Indicates the game the resource is for (<code>gta5<\/code>).<\/li>\n\n\n\n<li><strong>author, description, version<\/strong>: Metadata about your resource.<\/li>\n\n\n\n<li><strong>server_script &amp; client_script<\/strong>: Specifies the server and client scripts to be loaded.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"starting-the-resource-on-your-server\">Starting the Resource on Your Server<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Edit Your Server Configuration<\/strong>:Open your server&#8217;s configuration file, typically named <code>server.cfg<\/code>.<\/li>\n\n\n\n<li><strong>Add the Resource to the Configuration<\/strong>:Add the following line to ensure the <code>realtime<\/code> resource starts with the server:rubyCode kopieren<code>ensure realtime <\/code><strong>Note<\/strong>: If you&#8217;re using <code>start<\/code> instead of <code>zorg ervoor<\/code>, you can use: <code>start realtime<\/code><\/li>\n\n\n\n<li><strong>Save and Restart Your Server<\/strong>:After saving the changes to <code>server.cfg<\/code>, restart your FiveM server to load the new resource.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"full-resource-download\">Full Resource Download<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For convenience, here&#8217;s the complete set of files you need to create for the <code>realtime<\/code> resource.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-server-lua\">1. <code>server.lua<\/code><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"lua\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">RegisterNetEvent(\"realtime:event\")\nAddEventHandler(\"realtime:event\", function()\n    local hour = tonumber(os.date(\"%H\"))\n    local minute = tonumber(os.date(\"%M\"))\n    local second = tonumber(os.date(\"%S\"))\n    TriggerClientEvent(\"realtime:event\", source, hour, minute, second)\nend)\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-client-lua\">2. <code>client.lua<\/code><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"lua\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">local syncActive = true\nlocal syncThread = nil\n\n-- Function to start synchronization\nfunction StartRealTimeSync()\n    if not syncActive then\n        syncActive = true\n        syncThread = CreateThread(function()\n            while syncActive do\n                TriggerServerEvent(\"realtime:event\")\n                Wait(60000) -- Wait for 1 minute before next sync\n            end\n        end)\n    end\nend\n\n-- Function to stop synchronization\nfunction StopRealTimeSync()\n    if syncActive then\n        syncActive = false\n        if syncThread then\n            -- In Lua, threads are cooperative; setting syncActive to false will stop the loop\n            syncThread = nil\n        end\n    end\nend\n\nRegisterNetEvent(\"realtime:event\")\nAddEventHandler(\"realtime:event\", function(hour, minute, second)\n    if syncActive then\n        NetworkOverrideClockTime(hour, minute, second)\n    end\nend)\n\n-- Start synchronization on resource start\nStartRealTimeSync()\n\n-- Example: Command to toggle synchronization\nRegisterCommand(\"toggleTimeSync\", function()\n    if syncActive then\n        StopRealTimeSync()\n        print(\"Real-time synchronization stopped.\")\n    else\n        StartRealTimeSync()\n        print(\"Real-time synchronization started.\")\n    end\nend, false)\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-fxmanifest-lua\">3. <code>fxmanifest.lua<\/code><\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"lua\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">fx_version 'cerulean'\ngame 'gta5'\n\nauthor 'YourName'\ndescription 'Real-Time Synchronization Script for FiveM'\nversion '1.0.0'\n\nserver_script 'server.lua'\nclient_script 'client.lua'\n<\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Full Script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here you can download the script we&#8217;ve just created:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/codeload.github.com\/HiFiveM\/fivem-realtime\/zip\/refs\/heads\/main\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/HiFiveM\/fivem-realtime\/archive\/refs\/heads\/main.zip<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/github.com\/HiFiveM\/fivem-realtime\/tree\/main\/fivem-realtime\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/github.com\/HiFiveM\/fivem-realtime\/tree\/main\/fivem-realtime\" rel=\"noreferrer noopener\">Github<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ve successfully created a FiveM resource that synchronizes the in-game clock with real-world time. This script enhances the gaming experience by ensuring that the game environment reflects the actual time, adding a layer of realism for players.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>You can further customize the script by adjusting synchronization intervals, adding more commands, or integrating it with other server features.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Feel free to expand upon this foundation to suit your server&#8217;s unique needs!<\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial will guide you through creating a FiveM script that synchronizes the in-game clock with real-world time. This ensures that the game environment reflects the actual time, enhancing realism for players. We&#8217;ll cover both server-side and client-side scripting, adding functionality to start and stop the synchronization, and setting up the resource for your FiveM [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":193436,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2297,2298,2340],"tags":[3001,2928,3000],"class_list":["post-158437","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-free","category-scripts","category-lua-scripting","tag-fivem-script","tag-free","tag-free-script"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/posts\/158437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/comments?post=158437"}],"version-history":[{"count":0,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/posts\/158437\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/media\/193436"}],"wp:attachment":[{"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/media?parent=158437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/categories?post=158437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fivemx.com\/nl\/wp-json\/wp\/v2\/tags?post=158437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}