# Player functions

**Access Player properties and methods** After fetching a player instance, you can access its properties and methods using the dot (.) notation. For example, to get the player's username, use:

```lua
local username = newPlayer:GetUsername()
```

Similarly, you can call other methods available in the `Player` class, such as:

```lua
local id = newPlayer:GetId()
local character = newPlayer:GetCharacter()
local level = newPlayer:GetLevel()
```

To set properties, use the same dot notation:

```lua
newPlayer:SetUsername("NewUsername")
newPlayer:SetLevel(5)
```

**Interact with the PlayerManager** The `PlayerManager` allows you to interact with multiple players. To get the global instance of the `PlayerManager`, use:

```lua
local playerManager = PlayerManager:get()
```

Now you can call methods from the `PlayerManager` class:

```lua
local playerCount = playerManager:Count()
local player = playerManager:GetByConnectionId(connId)
local allPlayers = playerManager:GetAllPlayers()
```

**Iterate over all players** The `GetAllPlayers` function returns a table (Lua's version of an array) containing all players. To iterate over all players and perform actions, use a loop:

```lua
local allPlayers = playerManager:GetAllPlayers()
for _, player in ipairs(allPlayers) do
    local username = player:GetUsername()
    print("Player username: " .. username)
end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.tiltedphoques.com/tilted-online/guides/scripting/player-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
