> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PFLobbyLeave

> PFLobbyLeave reference for requesting that one or all local users leave a PlayFab lobby using the asynchronous PlayFab Multiplayer C++ SDK lobby APIs.

Request one or all local users to leave the lobby.

## Syntax

```cpp theme={null}
HRESULT PFLobbyLeave(  
    PFLobbyHandle lobby,  
    const PFEntityKey* localUser,  
    void* asyncContext  
)  
```

### Parameters

**`lobby`**   PFLobbyHandle

The handle of the lobby.

**`localUser`**   [PFEntityKey\*](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/pfentitykey_clientsdk)\
*optional*

An optional value to indicate if a specific local user should leave the lobby. If this value is nullptr, all local users will leave the lobby.

**`asyncContext`**   void\*\
*optional*

An optional, app-defined, pointer-sized context value that can be used to associate the completion state change with this call.

### Return value

Type: HRESULT

`S_OK` if the call succeeded or an error code otherwise. The human-readable form of the error code can be retrieved via [PFMultiplayerGetErrorMessage()](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayergeterrormessage).

## Remarks

This method queues an asynchronous operation to remove one or all local users from the lobby. On completion, a [PFLobbyLeaveLobbyCompletedStateChange](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/structs/pflobbyleavelobbycompletedstatechange) will be provided indicating that the operation has completed. <br /><br /> This method does not guarantee the leave will succeed. The operation may fail due to networking or service errors. If the leave attempt fails but is retriable, the library will continue to retry the leave operation. Otherwise, the local client will disconnect the requested local members from the lobby, but leave them as members. They will remain as disconnected members until they rejoin.   <br /><br /> This method cannot be called by a game\_server entity.

## Requirements

**Header:** PFLobby.h

## See also

[PFLobby members](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/pflobby_members)


## Related topics

- [Use lobby and matchmaking together](/services/playfab/multiplayer/lobby/lobby-and-matchmaking.md)
- [PFLobbyMemberRemovedStateChange](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/structs/pflobbymemberremovedstatechange.md)
- [PFLobbyMemberRemovedReason](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/enums/pflobbymemberremovedreason.md)
- [PFMultiplayerUninitialize](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pfmultiplayer/functions/pfmultiplayeruninitialize.md)
- [PFMultiplayer C/C++ API overview - PFLobby.h](/services/playfab/multiplayer/lobby/playfabmultiplayerreference-cpp/pflobby/pflobby_members.md)
