:WaitForData
Waits for data associated with realKey to become available in the local cache, up to an optional timeout.
This function is an essential utility for initial setup scripts. It efficiently waits for critical data to arrive without needing to write your own polling loops. Internally, it implicitly calls :Listen() if needed, ensuring a listener is active for the key.
DataReplicator:WaitForData(realKey: string, timeout?: number)
any?, boolean- A tuple containing:If data is found: data,
trueIf timed out or the key is invalid:
nil,false
-- In a script that initializes the player's UI.
print("Waiting for player data to load...")
local playerData, success = DataReplicator:WaitForData(`PlayerData_{player.UserId}`, 15) -- Wait up to 15s
if success then
print("Player data loaded! Initializing UI.")
-- Now it's safe to build the inventory, stats page, etc.
buildInventoryUI(playerData.Inventory)
updateStatsUI(playerData.Stats)
else
warn("Failed to load player data in time.")
-- Show an error message to the player.
endLast updated