: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?)
realKey: stringThe key of the data to update. The key must have been previously created or registered.
data: anyThe new data. This will completely overwrite the previous data for this key.
target: Player | {Player} | "All" | "AllExcept" | 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 theexceptTargetparameter (if they are listening).
boolean - true if the update was successfully queued, or false if the key is invalid or has not been registered.
-- 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 defaultLast updated