> For the complete documentation index, see [llms.txt](https://ans-dev.gitbook.io/datareplicator/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ans-dev.gitbook.io/datareplicator/introduction/setup-and-structure.md).

# Setup & Structure

Getting `DataReplicator` into your game is super easy!

{% stepper %}
{% step %}
**Get the Module**

You can grab the latest version directly from the Roblox Creator Store:&#x20;[**DataReplicator Model**](https://create.roblox.com/store/asset/115311304520674), or you can download the file here:

{% file src="/files/gMprOFYQB7MDP6fRgNtJ" %}
DataReplicator - File
{% endfile %}
{% endstep %}

{% step %}
**Place it in Your Game**

Once you have the `DataReplicator` [ModuleScript](https://create.roblox.com/docs/reference/engine/classes/ModuleScript) and its accompanying folders, the recommended place to put it is [ReplicatedStorage](https://create.roblox.com/docs/reference/engine/classes/ReplicatedStorage). This ensures it's easily accessible to both server [Scripts](https://create.roblox.com/docs/reference/engine/classes/Script) and client [LocalScripts](https://create.roblox.com/docs/reference/engine/classes/LocalScript).

The module is organized with its core logic and dependencies neatly separated for clarity and maintainability.

Your hierarchy in `ReplicatedStorage` should look like this:

```
ReplicatedStorage
└── DataReplicator (ModuleScript)       -- This is the main module you'll require
    ├── Dependencies (Folder)
    │   ├── Cryptography (ModuleScript) -- Handles encryption and secure key generation by @XoifailTheGod
    │   └── Signal (ModuleScript)       -- A lightweight event signal implementation by @AlexanderLindholt
    └── Internal (Folder)
        ├── Core (ModuleScript)         -- Handles all the internal logic
        └── Utilities (ModuleScript)    -- Contains helper functions
```

{% endstep %}

{% step %}
**Require the Module**

Now, you can easily access `DataReplicator` from your server scripts and client LocalScripts.

* **From a** [**Server Script**](https://create.roblox.com/docs/reference/engine/classes/Script) **(e.g., in `ServerScriptService`):**

  <pre class="language-lua" data-title="MyTestScript.luau"><code class="lang-lua">-- Location: ServerScriptService/MyTestScript

  local ReplicatedStorage = game:GetService("ReplicatedStorage")
  local DataReplicator = require(ReplicatedStorage.DataReplicator)

  local UPTIME_KEY = "ServerUptime"

  -- Create the data key with an initial value
  local success = DataReplicator:Create(UPTIME_KEY, math.floor(os.clock()))
  if success then
  	print("[Server] DataReplicator key 'ServerUptime' created successfully.")
  end

  -- Continuously update the data every 5 seconds
  task.spawn(function()
  	while true do
  		task.wait(5)
  		local newUptime = math.floor(os.clock())
  		DataReplicator:Update(UPTIME_KEY, newUptime, "All")
  		print(`[Server] Updated 'ServerUptime' to: {newUptime}`)
  	end
  end)
  </code></pre>
* **From a** [**LocalScript**](https://create.roblox.com/docs/reference/engine/classes/LocalScript) **(e.g., inside a StarterPlayerScripts in `StarterPlayer`):**

  <pre class="language-lua" data-title="MyClientTest.luau"><code class="lang-lua">-- Location: StarterPlayer/StarterPlayerScripts/MyClientTest

  local ReplicatedStorage = game:GetService("ReplicatedStorage")
  local DataReplicator = require(ReplicatedStorage.DataReplicator)

  local UPTIME_KEY = "ServerUptime"

  print("[Client] Setting up listener for 'ServerUptime'...")

  -- Listen for changes to the key
  local uptimeSignal = DataReplicator:Listen(UPTIME_KEY)

  uptimeSignal:Connect(function(newUptime)
  	if newUptime then
  		print(`[Client] Received new server uptime: {newUptime}`)
  	else
  		print("[Client] 'ServerUptime' data was deleted.")
  	end
  end)
  </code></pre>

{% endstep %}
{% endstepper %}

And that's it! If you run your game with these two scripts, you will see the server printing its updates and the client printing the data it receives in real-time in your output console. You're all set to start using `DataReplicator` in your project.
