:Delete
Deletes a data entry on the server. This will also remove the key from the registry.
If any clients are currently listening to this realKey, they will be notified of the deletion. Their local cache for the key will be cleared, and their listener signal will fire with nil. Like updates, deletions are efficiently batched.
DataReplicator:Delete(realKey: string)
realKey: stringThe key of the data to delete.
boolean - true if the data was found and successfully deleted, or false if the key was invalid or did not exist.
-- Example 1: Deleting a temporary event key after it has ended.
local EVENT_KEY = "Public_WeekendBonusXP"
-- (Some time later, after the event is over...)
local success = DataReplicator:Delete(EVENT_KEY)
if success then
print(`[Server] Deleted event key: {EVENT_KEY}. Clients will be notified.`)
end
-- Example 2: Cleaning up a player's data when they leave the game.
local Players = game:GetService("Players")
Players.PlayerRemoving:Connect(function(player)
local userId = player.UserId
local playerDataKey = `PlayerData_{userId}`
-- Delete their main data entry
DataReplicator:Delete(playerDataKey)
-- Also delete any other related data
local playerSettingsKey = `PlayerSettings_{userId}`
DataReplicator:Delete(playerSettingsKey)
print(`[Server] Cleaned up all replicated data for player {userId}.`)
end)Last updated