# LiveSync Setup

## How It Works

Live Sync is a feature that pushes data changes from your Auxvyn dashboard directly to your live Roblox game servers in real time, the moment you save a change in the dashboard, every server running your game receives it instantly.

***

### The Problem It Solves

Without Live Sync, if you edit a player's data in the dashboard while they are in game, nothing happens until they rejoin. Their game server still has the old value in memory. Live Sync eliminates this by bridging your dashboard and your live game servers.

{% hint style="info" %}
Enabling LiveSync is **highly** recommended if you plan on editing player data.
{% endhint %}

***

### How It Works Under the Hood

```
You edit a record in the dashboard
            ↓
Auxvyn saves the change to the database
            ↓
Auxvyn calls the Roblox Open Cloud API
            ↓
Roblox MessagingService broadcasts the change
to every live server running your game
            ↓
Each server receives the message instantly
            ↓
Your callback fires — you apply the change
to the player if they are in that server
```

The key component is **Roblox MessagingService,** a built-in Roblox system that lets servers in the same game communicate with each other in real time. Auxvyn uses the Open Cloud API to publish messages into your game from outside Roblox.

***

### What You Need

* An Auxvyn workspace with a Universe ID set
* A **Roblox Open Cloud API key** with MessagingService publish permission
* The Auxvyn Lua module version 1.1.0 or later
* A published Roblox game

***

### Setting Up Live Sync

#### Step 1 — Create an Open Cloud API Key

1. Go to [create.roblox.com/dashboard/credentials](https://create.roblox.com/dashboard/credentials)
2. Click **Create API Key**
3. Give it a name like `Auxvyn Live Sync`
4. Under **Access Permissions**, find **Messaging Service** and add it
5. Set the permission to **Publish**
6. Under **Accepted IP Addresses**, you can leave this open
7. Set an expiry or leave it as never expires
8. Click **Save**
9. Copy the generated API key, you will only see it once

***

#### Step 2 — Add the Key to Your Workspace

1. Go to your Auxvyn dashboard and open your workspace
2. Click the **Settings** tab
3. Scroll down to the **Live Sync** section
4. Paste your Open Cloud API key into the input field
5. Click **Save key**

You will see a green **Live sync** badge appear in your workspace header confirming it is active.

***

#### Step 3 — Add Live Sync to Your Game Script

In your server Script, call `Auxvyn.startLiveSync()` after `Auxvyn.init()`:

```lua
local Auxvyn = require(game.ServerScriptService.Auxvyn)
Auxvyn.init("auxvyn_your_key_here")

Auxvyn.startLiveSync(function(userId, key, value, player)
    if not player then return end

    -- Handle whichever keys your game uses
    if key == "coins" then
        local leaderstats = player:FindFirstChild("leaderstats")
        if leaderstats then
            local coins = leaderstats:FindFirstChild("Coins")
            if coins then
                coins.Value = tonumber(value) or coins.Value
            end
        end
    end
end)
```

***

#### Step 4 — Publish and Test

1. Publish your game to Roblox
2. Join the live game from the Roblox app or website — **not Studio**
3. Open your Auxvyn dashboard and go to the **Database** tab
4. Find your player and edit a value
5. Watch the change apply instantly in game

{% hint style="warning" %}
Live Sync does not work in Studio playtesting. This is a Roblox limitation — MessagingService is disabled in Studio entirely. You must test in a published live game.
{% endhint %}

***

### Handling Multiple Keys

Your `startLiveSync` callback can handle as many keys as your game needs:

```lua
Auxvyn.startLiveSync(function(userId, key, value, player)
    if not player then return end

    if key == "coins" then
        player.leaderstats.Coins.Value = tonumber(value) or 0

    elseif key == "level" then
        player.leaderstats.Level.Value = tonumber(value) or 1

    elseif key == "banned" and value == true then
        player:Kick("You have been banned from this game.")

    elseif key == "vip" then
        -- grant or remove VIP perks
        updateVipStatus(player, value)
    end
end)
```

***

### Player Not in This Server

The `player` parameter in the callback is `nil` if the affected player is not in the current server. This is normal, your game might be running on multiple servers and the message is broadcast to all of them. Always check for `nil`:

```lua
Auxvyn.startLiveSync(function(userId, key, value, player)
    if not player then
        -- Player is not in this server, nothing to do
        return
    end

    -- Safe to use player here
end)
```

***

### Troubleshooting

**The callback never fires**

* Make sure you are testing in a published live game, not Studio
* Check that your Open Cloud key has **Messaging Service → Publish** permission
* Make sure the Universe ID in your workspace settings matches your game
* Confirm `Auxvyn.init()` printed a successful connection message

**I see a subscription error in output**

{% hint style="danger" %}
\[Auxvyn] MessagingService subscription failed: ...
{% endhint %}

This usually means MessagingService is not available for your experience. Check that your game is published and not restricted in Creator Dashboard settings.

**The value updates but nothing changes in game**

Your callback is firing but your code inside it isn't applying the change correctly. Add a print statement to confirm the callback is receiving the right key and value:

```lua
Auxvyn.startLiveSync(function(userId, key, value, player)
    print("[Debug] Received:", userId, key, tostring(value), player and player.Name or "not in server")
end)
```

***

### Security

The Open Cloud key you save in Auxvyn is:

* Stored server-side only, never returned to the client or browser
* Only used to publish messages to your specific Universe ID
* Never exposed in API responses or logs

If you believe your Open Cloud key has been compromised, revoke it immediately in the Roblox Creator Dashboard and generate a new one, then update it in your workspace settings.

***

### What's Next


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://auxvyn.gitbook.io/auxvyn-docs/tutorials/livesync-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
