Class PlayersSingleton

Access using Airship.Players. Players singleton allows you to work with currently connected clients (with Airship's Player object).

If you are looking to get information about offline users see AirshipUserController

Methods

  • Adds a bot player to your game server. This player will function similarly to a real player.

    Returns Player

  • Search for an online player by connection id.

    Parameters

    • connectionId: number

      The connection id to match.

    Returns undefined | Player

    The player with target connectionId if one exists.

  • Tries to find an online player with a username similar to searchName. If an exact match is found that player will be returned. This search is not case sensitive.

    Parameters

    • searchName: string

      The target username to match.

    Returns undefined | Player

  • Searches for online player by userId.

    Parameters

    • userId: string

      Target user id to match.

    Returns undefined | Player

    Player with user id if one exists, otherwise undefined.

  • Searches for online player by username. This is case sensitive. For a more lenient username search see FindByFuzzySearch.

    Parameters

    • name: string

      Target username -- this must match the player's username exactly.

    Returns undefined | Player

    An online player with matching username if one exists, otherwise undefined.

  • Gets a user's profile picture as Texture2D.

    Parameters

    • userId: string

      Id of user you want to get profile picture of. This player doesn't need to be online.

    • useLocalCache: boolean = true

      If true this function will return values cached locally. This is usually preferable unless you need to guarantee the most up-to-date profile picture. Defaults to true.

    Returns Promise<Texture2D>

    A Texture2D of the profile picture. If this function fails to fetch the profile picture or it doesn't exist it will return the default profile picture for the user.

  • Only called in LuauContext.Game

    Returns void

  • Observe every player entering/leaving the game. The returned function can be called to stop observing.

    Parameters

    • observer: ((player) => void | (() => void))

      Function fired for every player currently in the game and every future player that joins. The observer function must return another function which is called when said player leaves (or the top-level observer function was called to stop the observation process).

      Airship.players.ObservePlayers((player) => {
      print(`${player.name} entered`);
      return () => {
      print(`${player.name} left`);
      };
      });
        • (player): void | (() => void)
        • Parameters

          Returns void | (() => void)

    • Optional signalPriority: SignalPriority

    Returns (() => void)

    Disconnect function -- call to stop observing players and call the cleanup function on each.

      • (): void
      • Returns void

  • Waits for player by connectionId. This is only useful if you are working with a connection id before a player has been added. A player is added when the client loads the starting scene. On client your local player will exist immediately.

    Parameters

    • connectionId: number

      The connection id to wait for

    • timeoutSec: number = 5

      How long (in seconds) to stop waiting for this player.

    Returns Promise<undefined | Player>

    Player with connectionId if found, otherwise undefined after timeout.