# PlayerData: get() method

> The get() method of the PlayerData interface resolves with a key's value and version, or undefined when the key has none.

The **`get()`** method of the [`PlayerData`](/docs/room/player-data) interface resolves with a key's value and version, or `undefined` when the key has none.

## Syntax

```ts
get(key)
get<T>(key)
```

### Parameters

`key`
: The key, 1 to 64 of `A-Z a-z 0-9 _ . : -`.

### Return value

A `Promise` that resolves with `{ value, version }`, or `undefined`. `value` is JSON or a `Uint8Array`; the type parameter `T` types it, without checking it.

### Exceptions

The promise rejects with a [`DataError`](/docs/room/data-error), such as `E_INVALID` for a malformed key or `E_UNAVAILABLE` when the data service can't be reached.

## Description

A `get()` within 5 seconds of the room's last read or write of the same key is answered from memory, with no call; a hit doesn't extend those 5 seconds. Writes by other rooms, clients or your backend show within 5 seconds, or at once after [`refresh()`](/docs/room/player-data/refresh). Each `get()` resolves with its own copy of the value.

Load what a player needs once, in `onJoin`, rather than calling `get()` every tick.

## Examples

### Applying a player's chosen skin

```ts
// skins.ts
import { defineRoom, defineSchema, entity } from "@irtio/room";

const Avatar = entity("avatar", { owner: "string", skin: "string" }, { key: "owner" });

export default defineRoom({
  schema: defineSchema({ entities: [Avatar] }),
  async onJoin(room, connection) {
    const skin = await room.playerData(connection.player).get<string>("skin");
    const avatar = room.entities.get(Avatar, connection.player) ?? room.entities.create(Avatar, { owner: connection.player });
    avatar.skin = skin?.value ?? "default";
  },
});
```

## See also

- [`PlayerData.set()`](/docs/room/player-data/set)
- [The cache in the room](/docs/room/guides/player-data#the-cache-in-the-room)
