how to execute a function when a client leaves and when a host leaves?

how do i execute a function when a client leaves and when a host leaves?

There is a OnClientDisconnectCallback you can subscribe to on the NetworkManager.