@rbxts/fletchette
    Preparing search index...

    Class PropertyPacket<T>

    PropertyPacket is a wrapper around SignalPacket that provides a type-safe way to send data between server and client. This implements a property system where the value can be set for all players, a specific player, or a filtered list of players.

    Type Parameters

    • T

      The type of the property

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a new PropertyPacket.

      Type Parameters

      • T

      Parameters

      • id: string

        The id of the property

      • OptionalinitialValue: T

        The initial value of the property

      • OptionalisUnreliable: boolean

        Whether the property should be sent unreliably. Default is false.

      • Optionalmeta: Many<["tuple", [value: SerializerMetadata<T>], undefined]>

        Metadata for the serializer

      Returns PropertyPacket<T>

    Properties

    changed: Signal<(value: T) => void>

    Signal that fires when the property changes. Should only be used on the client since the server does not listen for changes.

    className: "PropertyPacket"

    Class name of the packet, used for debugging purposes.

    perPlayer?: Map<Player, undefined | T>

    Map of player to their property value

    signalPacket: SignalPacket<(value: T) => void>

    SignalPacket used to send the property

    Methods

    • Clears the value of the property for players that pass the predicate. Should only be used on the server.

      Parameters

      • predicate: (player: Player) => boolean

        The predicate to filter players

      Returns void

    • Clears the value of the property. This will clear the perPlayer map and fire the signal to all players. Should only be used on the server.

      Parameters

      • player: Player

      Returns void

    • Returns the current value of the property.

      Parameters

      • Optionalplayer: Player

        The player to get the value for. Does nothing on the client.

      Returns T

      The current value of the property

    • Returns the value of the property for a specific player. Should only be used on the server.

      Parameters

      • player: Player

        The player to get the value for

      Returns T

      The value of the property for the player

      Use get instead.

    • Observes the property for changes. Unlike changed, this will fire the handler immediately if the value is already set. Else, it will wait for the value to be set and then fire the handler.

      Parameters

      • handler: (value: T) => void

        The handler to call when the property changes

      Returns Connection

      A connection that can be disconnected to stop observing the property

    • Sets the value of the property. This will clear the perPlayer map and fire the signal to all players. Should only be used on the server.

      Parameters

      • value: T

        The new value of the property

      Returns void

    • Sets the value of the property for players that pass the predicate. Should only be used on the server.

      Parameters

      • predicate: (player: Player) => boolean

        The predicate to filter players

      • value: T

        The new value of the property

      Returns void

    • Sets the value of the property for a specific player. Should only be used on the server.

      Parameters

      • player: Player

        The player to set the value for

      • value: T

        The new value of the property

      Returns void

    • Sets the value of the property for a list of players. Should only be used on the server.

      Parameters

      • players: Player[]

        The list of players to set the value for

      • value: T

        The new value of the property

      Returns void

    • Sets the value of the property for players that do not have a value set. Should only be used on the server.

      Parameters

      • value: T

        The new value of the property

      Returns void