:Create
Creates a new, replicated data entry on the server. Once created, this data can be requested or listened to by clients (subject to authorization).
If the key has not been pre-registered with :RegisterKey(), this function will also register it. Any options provided here will be locked in for the lifetime of the key.
DataReplicator:Create(realKey: string, data: any, options: table?)
realKey: stringThe unique, case-sensitive key for the data. Must not already exist.
data: anyThe initial data to be stored. Can be any Roblox-serializable type.
options: table?An optional dictionary to configure advanced features for this data key.
Encrypted: boolean - (Default:false) Iftrue, all data for this key will be protected by transport encryption. A unique session key is securely established for each player using a post-quantum key exchange. Best for sensitive information like currency or private settings.Priority: string - (Default:"Medium") Sets the update priority. Can be"High","Medium", or"Low". Use"High"for critical gameplay data.UseDeltaCompression: boolean - (Default:false) Iftrue, only changes within a table will be replicated after the initial full sync. Highly recommended for large tables like inventories or skill trees to save network bandwidth.
boolean - true if the data was created successfully, or false if the key is invalid or already exists.
-- Example 1: Creating a simple, public data key for server announcements.
DataReplicator:Create("Public_ServerAnnouncements", "Welcome to the game!")
-- Example 2: Creating a complex, high-priority, and delta-compressed table for player data.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local userId = player.UserId
local playerDataKey = `PlayerData_{userId}`
local initialData = {
Level = 1,
XP = 0,
Gold = 100,
Inventory = {},
Stats = { Strength = 5, Agility = 5, Intellect = 5 }
}
local success = DataReplicator:Create(playerDataKey, initialData, {
Priority = "High",
UseDeltaCompression = true
})
if success then
print(`Initial data created for player {userId}`)
end
end)
-- Example 3: Creating a sensitive data key that will be encrypted.
local success = DataReplicator:Create("Private_GameSettings", { Volume = 0.5, Graphics = "High" }, {
Encrypted = true
})
if success then
print("Private, encrypted game settings have been created.")
endLast updated