# EntityStore: ownerOf() method

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

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

## Syntax

```ts
ownerOf(entity)
```

### Parameters

`entity`
: A [`ClientEntity`](/docs/client/client-entity).

### Return value

A string, the owner's player ID, or `undefined` when the room owns the entity or the client doesn't hold it.

### Exceptions

None.

## Description

The owner arrives with the entity and with each change of owner, which [`onOwner()`](/docs/client/entity-store/onowner) follows. Compare the result with [`room.player`](/docs/client/room-client/player) to tell whether the local player owns an entity, or use [`mine()`](/docs/client/entity-store/mine) to list the ones it owns.

## Examples

### Labelling each ship with its pilot

The client shows whose each ship is, and marks the player's own.

```ts
// pilots.ts
import { connect, defineSchema, entity } from "@irtio/client";

const Ship = entity("ship", { x: "f32", y: "f32" });
const schema = defineSchema({ entities: [Ship] });

const room = await connect("sector-4", { schema });

room.entities.onEnter(Ship, (ship) => {
  const pilot = room.entities.ownerOf(ship);
  if (pilot === undefined) console.log(`ship ${ship.id} drifts unpiloted`);
  else console.log(`ship ${ship.id} flown by ${pilot === room.player ? "you" : pilot}`);
});
```

## See also

- [`EntityStore.onOwner()`](/docs/client/entity-store/onowner)
- [`Entities.ownerOf()`](/docs/room/entities/ownerof), the room's side
- [Ownership](/docs/room/guides/ownership)
