> 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/api-reference/server-side-api/update.md).

# :Update

Updates an existing data entry on the server. Any clients currently listening to this `realKey` (and match the `target` criteria) will receive the update.

All updates are queued and sent efficiently in a single batch per player at the end of the server tick, ensuring minimal network overhead.

***

**`DataReplicator:Update(realKey: string, data: any, target?, exceptTarget?)`**

***

{% tabs %}
{% tab title="Parameters" %}

* `realKey`: [string](https://create.roblox.com/docs/luau/strings)

  The key of the data to update. The key must have been previously created or registered.
* `data`: any

  The new data. This will completely overwrite the previous data for this key.
* `target`: [Player](https://create.roblox.com/docs/reference/engine/classes/Player) | {[Player](https://create.roblox.com/docs/reference/engine/classes/Player)} | "All" | "AllExcept" | [nil](https://create.roblox.com/docs/luau/nil) (Optional)

  Specifies which clients should receive this update.

  * `nil` (Default): Sends to **all clients** that are currently listening to this specific realKey.
  * `Player`: Sends **only** to the specified player (if they are listening).
  * `{Player}` (Table of Players): Sends to **all players** in the table (if they are listening).
  * "`All"`: Sends to **all online players** who are listening.
  * `"AllExcept"`: Sends to **all online players** except those specified in the `exceptTarget` parameter (if they are listening).
* `exceptTarget`: [Player](https://create.roblox.com/docs/reference/engine/classes/Player) | {[Player](https://create.roblox.com/docs/reference/engine/classes/Player)} | [nil](https://create.roblox.com/docs/luau/nil) (Optional)

  Used only when target is set to `"AllExcept"`. Specifies which player or table of players to exclude from the update.
  {% endtab %}

{% tab title="Returns" %}
[`boolean`](https://create.roblox.com/docs/luau/booleans) - `true` if the update was successfully queued, or `false` if the key is invalid or has not been registered.
{% endtab %}

{% tab title="Example" %}
{% code title="UpdateData.luau" %}

```lua
-- Assume this key was created earlier for a specific player
local playerDataKey = `PlayerData_{player.UserId}`

-- Example 1: Updating a player's gold.
-- The target is the specific player object. Only this player will receive the update.
local newGold = 1500
DataReplicator:Update(playerDataKey, { Gold = newGold }, player)


-- Example 2: Announcing a server-wide maintenance warning.
-- The target is "All" players. Every listening client will receive this.
local announcementKey = "Public_ServerAnnouncements"
DataReplicator:Update(announcementKey, "Server restarting in 5 minutes!", "All")


-- Example 3: Giving a team a score update, excluding one player.
local blueTeamPlayers = {player1, player2, player3}
local mvpPlayer = player2 -- Maybe the MVP gets a special, separate notification

local teamScoreKey = "TeamScore_Blue"
DataReplicator:Update(teamScoreKey, 500, "AllExcept", mvpPlayer)


-- Example 4: Sending an update only to players in a specific table.
-- Useful for party systems or instanced content.
local partyMembers = {player4, player5}
local partyQuestKey = "PartyQuest_Main"
DataReplicator:Update(partyQuestKey, "New objective: Defeat the Dragon!", partyMembers)


-- Example 5: Sending an update to ALL listeners for a key (default behavior).
-- This is useful if you don't need specific targeting.
local worldStateKey = "WorldState"
DataReplicator:Update(worldStateKey, { IsRaining = true }) -- target is nil by default
```

{% endcode %}
{% endtab %}
{% endtabs %}
