> For the complete documentation index, see [llms.txt](https://ans-dev.gitbook.io/datareplicator/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ans-dev.gitbook.io/datareplicator/api-reference/client-side-api/waitfordata.md).

# :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()`](/datareplicator/api-reference/client-side-api/listen.md) if needed, ensuring a listener is active for the key.

***

**`DataReplicator:WaitForData(realKey: string, timeout?: number)`**

***

{% tabs %}
{% tab title="Parameters" %}

* `realKey`: [string](https://create.roblox.com/docs/luau/strings)

  The original data key you are waiting for.
* `timeout`: [number](https://create.roblox.com/docs/luau/numbers)? (Optional)

  The maximum time to wait in seconds. Defaults to `5 seconds`.
  {% endtab %}

{% tab title="Returns" %}

* `any?, boolean` - A tuple containing:
  * If data is found: data, `true`
  * If timed out or the key is invalid: `nil`, `false`

***

<br>
{% endtab %}

{% tab title="Example" %}
{% code title="WaitForData.luau" %}

```lua
-- 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.
end
```

{% endcode %}
{% endtab %}
{% endtabs %}
