:GetServerData
Retrieves data directly from the server's internal storage.
This function provides immediate, synchronous access to the current state of any replicated data. It is intended for server-to-server communication only and should not be used as a substitute for client communication.
DataReplicator:GetServerData(realKey: string)
realKey: stringThe key of the data to retrieve.
any | nil - The current data associated with the key, or nil if the key does not exist.
-- In a different server script, for example, a quest completion script.
local function onQuestCompleted(player, questId)
local userId = player.UserId
local playerDataKey = `PlayerData_{userId}`
-- Retrieve the player's current data directly from DataReplicator's storage.
local currentPlayerData = DataReplicator:GetServerData(playerDataKey)
if currentPlayerData then
-- Create a deep copy to modify
local newPlayerData = HttpService:JSONDecode(HttpService:JSONEncode(currentPlayerData))
-- Modify the data based on quest rewards
newPlayerData.XP += 100
newPlayerData.Gold += 50
table.insert(newPlayerData.CompletedQuests, questId)
-- Update the data in DataReplicator, which will then replicate the changes to the client.
DataReplicator:Update(playerDataKey, newPlayerData, player)
print(`[QuestSystem] Player {player.Name} completed quest {questId} and received rewards.`)
else
warn(`[QuestSystem] Could not find player data for {player.Name} to grant rewards.`)
end
endLast updated