# Entities: ownerOf() method

> The ownerOf() method of the Entities interface returns the player who owns an entity, or undefined when the room owns it.

The **`ownerOf()`** method of the [`Entities`](/docs/room/entities) interface returns the player who owns an entity, or `undefined` when the room owns it.

## Syntax

```ts
ownerOf(entity)
```

### Parameters

`entity`
: The [`RoomEntity`](/docs/room/room-entity) to ask about.

### Return value

The owner's player ID, a string, or `undefined` for the room.

### Exceptions

`Error`
: Thrown if `entity` isn't a live entity of the room's `entities`, such as one already deleted, or `room.state`.

`TypeError`
: Thrown if `entity` isn't an entity object.

## Examples

### Letting only a card's holder play it

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

const Card = entity("card", { suit: "u8", rank: "u8", played: "bool" });

export default defineRoom({
  schema: defineSchema({ entities: [Card] }),
  onMessage(room, connection, message) {
    const id = (message as { play?: unknown } | null)?.play;
    const card = typeof id === "number" ? room.entities.get(id) : undefined;
    if (card?.kind !== Card || room.entities.ownerOf(card) !== connection.player) return;
    card.played = true;
    room.entities.setOwner(card, undefined);
  },
});
```

## See also

- [`Entities.setOwner()`](/docs/room/entities/setowner)
- [Ownership](/docs/room/guides/ownership)
