# 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
```
