Skip to main content

PlayerMockServiceClient

This item only works when running on the client. Client

Client-side counterpart to PlayerMockService -- one instance stands in for one simulated client. Discovery and leak detection live in [PlayerMockServiceBase]: this service sees a server bag's mocks the way a real client sees the players the server admitted, and multiple client services (simulated clients) may coexist.

A headless test has no Players.LocalPlayer, so a test designates a PlayerMock as the local player for the client realm. The service records the designation per instance -- this simulated client's local player, read back with PlayerMockServiceClient.GetLocalPlayer -- and mirrors it into the ambient global read by bag-less call sites (Players.LocalPlayer or PlayerMock.getMockedLocalPlayer()).

Designation may happen before the bag boots -- PlayerMock.setMockedLocalPlayer(player) directly, matching production where Players.LocalPlayer exists before any service runs -- and [Init] adopts the pre-boot designation as this client's local player, owning its cleanup. Note the ambient global holds a single designation, so concurrent simulated clients are distinct only through their services; ambient readers (e.g. dummy-mode Remoting) see the most recent designation.

local playerMockServiceClient = clientServiceBag:GetService(require("PlayerMockServiceClient"))
playerMockServiceClient:SetLocalPlayer(player)

Functions

SetLocalPlayer

PlayerMockServiceClient:SetLocalPlayer(
playerPlayer--

must be a PlayerMock

) → ()

Designates the given PlayerMock as this simulated client's local player, and mirrors it into the ambient global. Cleared automatically when the service is destroyed (unless another mock has since taken the ambient designation over).

GetLocalPlayer

PlayerMockServiceClient:GetLocalPlayer() → Player?

Returns this simulated client's local player -- the designation this service made or adopted at [Init] -- or nil. Unlike PlayerMock.getMockedLocalPlayer, this survives another client service designating a different mock.

Show raw api
{
    "functions": [
        {
            "name": "SetLocalPlayer",
            "desc": "Designates the given [PlayerMock] as this simulated client's local player, and mirrors it into\nthe ambient global. Cleared automatically when the service is destroyed (unless another mock has\nsince taken the ambient designation over).",
            "params": [
                {
                    "name": "player",
                    "desc": "must be a PlayerMock",
                    "lua_type": "Player"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 57,
                "path": "src/player-mock/src/Client/PlayerMockServiceClient.lua"
            }
        },
        {
            "name": "GetLocalPlayer",
            "desc": "Returns this simulated client's local player -- the designation this service made or adopted at\n[Init] -- or nil. Unlike [PlayerMock.getMockedLocalPlayer], this survives another client service\ndesignating a different mock.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Player?"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 71,
                "path": "src/player-mock/src/Client/PlayerMockServiceClient.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "PlayerMockServiceClient",
    "desc": "Client-side counterpart to [PlayerMockService] -- one instance stands in for one simulated\nclient. Discovery and leak detection live in [PlayerMockServiceBase]: this service sees a server\nbag's mocks the way a real client sees the players the server admitted, and multiple client\nservices (simulated clients) may coexist.\n\nA headless test has no `Players.LocalPlayer`, so a test designates a [PlayerMock] as the local\nplayer for the client realm. The service records the designation per instance -- *this* simulated\nclient's local player, read back with [PlayerMockServiceClient.GetLocalPlayer] -- and mirrors it\ninto the ambient global read by bag-less call sites\n(`Players.LocalPlayer or PlayerMock.getMockedLocalPlayer()`).\n\nDesignation may happen *before* the bag boots -- `PlayerMock.setMockedLocalPlayer(player)`\ndirectly, matching production where `Players.LocalPlayer` exists before any service runs -- and\n[Init] adopts the pre-boot designation as this client's local player, owning its cleanup. Note\nthe ambient global holds a single designation, so concurrent simulated clients are distinct only\nthrough their services; ambient readers (e.g. dummy-mode Remoting) see the most recent\ndesignation.\n\n```lua\nlocal playerMockServiceClient = clientServiceBag:GetService(require(\"PlayerMockServiceClient\"))\nplayerMockServiceClient:SetLocalPlayer(player)\n```",
    "realm": [
        "Client"
    ],
    "source": {
        "line": 29,
        "path": "src/player-mock/src/Client/PlayerMockServiceClient.lua"
    }
}