Skip to main content

playerHumanoidUtil

A simple utility module for working with the player's humanoid.

Functions

playerHumanoid

playerHumanoidUtil.playerHumanoid(playerPlayer) → Humanoid?

Attempts to return the given player's humanoid, if found. This method is sugar for:

local function playerHumanoid(player: Player)
	return if player.Character ~= nil then 
		player.Character:FindFirstChildWhichIsA("Humanoid") 
	else 
		nil
end

playerHumanoidPromise

playerHumanoidUtil.playerHumanoidPromise(playerPlayer) → Promise<Humanoid>

Promisfied verison of playerHumanoidUtil.playerHumanoid.

Automatic promise cancellation

The returned promise will be cancelled automatically once player is no longer in game!

trySeatPlayerPromise

playerHumanoidUtil.trySeatPlayerPromise(
playerPlayer,
seatVehicleSeat | Seat
) → Promise<Seat | VehicleSeat>

Attempts to seat the given player's humanoid to seat. Additionally, if the player's humanoid is already seated on some other seat, then the humanoid will be unseated through humanoid.Sit = false before being seated to seat.

WARNING
  • This method will throw an error if player is not preset in game.

  • On the client, this method will throw an error if player is not the local player.

  • If the given seat already has an Occupant which is not the player's humanoid, then the returned promise will reject.

Automatic promise cancellation

The returned promise will be cancelled automatically once player is no longer in game!

forceSeatPlayerPromise

playerHumanoidUtil.forceSeatPlayerPromise(
playerPlayer,
seatVehicleSeat | Seat
) → Promise<Seat | VehicleSeat>

Works almost exactly the same as playerHumanoidUtil.trySeatPlayerPromise, but unlike the former method, this method will try to unseat the seat's occupant (if any) through humanoid.Sit = false.

WARNING
  • This method will throw an error if player is not preset in game.

  • On the client, this method will throw an error if player is not the local player.

  • If the given seat already has an Occupant which is not the player's humanoid, then the returned promise will reject.

Automatic promise cancellation

The returned promise will be cancelled automatically once player is no longer in game!

playerHumanoidSeatPartObserver

playerHumanoidUtil.playerHumanoidSeatPartObserver(
playerPlayer,
observerSeated((seatPlayerIsSittingOnSeat | VehicleSeat) → ())?,
observerUnseated((seatPlayerIsNoLongerSittingOn(Seat | VehicleSeat)?) → ())?
) → Connection
playerHumanoidUtil.playerHumanoidSeatPartObserver(player, function(seatPlayerIsSittingOn)
	print(player.Name .. " sat on seat " ..tostring(newSeatPlayerIsSittingOn.Name))		
end, function(seatPlayerIsNoLongerSittingOn)
	if newSeatPlayerIsNoLongerSittingOn ~= nil then 
		print(player.Name .. " left seat " ..tostring(newSeatPlayerIsNoLongerSittingOn.Name))		
	end
end)

Observes the given player's humanoid.SeatPart, but also accounting for cases where the player's humanoid has not being loaded yet or if the player's humanoid is updated (for e.g on character respawn).

Show raw api
{
    "functions": [
        {
            "name": "playerHumanoid",
            "desc": " \nAttempts to return the given `player`'s humanoid, if found. This method is sugar for:\n\n```lua\nlocal function playerHumanoid(player: Player)\n\treturn if player.Character ~= nil then \n\t\tplayer.Character:FindFirstChildWhichIsA(\"Humanoid\") \n\telse \n\t\tnil\nend\n```",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Humanoid?\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 39,
                "path": "src/playerHumanoidUtil/init.luau"
            }
        },
        {
            "name": "playerHumanoidPromise",
            "desc": " \nPromisfied verison of [playerHumanoidUtil.playerHumanoid].\n\n:::note Automatic promise cancellation\nThe returned promise will be cancelled automatically once `player` is no longer in game!\n:::",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<Humanoid>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 55,
                "path": "src/playerHumanoidUtil/init.luau"
            }
        },
        {
            "name": "trySeatPlayerPromise",
            "desc": "Attempts to seat the given `player`'s humanoid to `seat`. Additionally, if the `player`'s humanoid is already seated on some *other* seat,\nthen the humanoid will be unseated through `humanoid.Sit = false` before being seated to `seat`.\n\n:::warning\n- This method will throw an error if `player` is not preset in game.\n\n- On the client, this method will throw an error if `player` is not the local player.\n\n- If the given `seat` already has an `Occupant` which is not the `player`'s humanoid, then the returned promise\nwill reject.\n:::\n\n:::note Automatic promise cancellation\nThe returned promise will be cancelled automatically once `player` is no longer in game!\n:::",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "seat",
                    "desc": "",
                    "lua_type": "VehicleSeat | Seat"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<Seat | VehicleSeat>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 124,
                "path": "src/playerHumanoidUtil/init.luau"
            }
        },
        {
            "name": "forceSeatPlayerPromise",
            "desc": "Works almost exactly the same as [playerHumanoidUtil.trySeatPlayerPromise], but unlike the former method, this method\nwill try to unseat the `seat`'s occupant (if any) through `humanoid.Sit = false`.\n\n:::warning\n- This method will throw an error if `player` is not preset in game.\n\n- On the client, this method will throw an error if `player` is not the local player.\n\n- If the given `seat` already has an `Occupant` which is not the `player`'s humanoid, then the returned promise\nwill reject.\n:::\n\n:::note Automatic promise cancellation\nThe returned promise will be cancelled automatically once `player` is no longer in game!\n:::",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "seat",
                    "desc": "",
                    "lua_type": "VehicleSeat | Seat"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<Seat | VehicleSeat>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 181,
                "path": "src/playerHumanoidUtil/init.luau"
            }
        },
        {
            "name": "playerHumanoidSeatPartObserver",
            "desc": " \n\n```lua\nplayerHumanoidUtil.playerHumanoidSeatPartObserver(player, function(seatPlayerIsSittingOn)\n\tprint(player.Name .. \" sat on seat \" ..tostring(newSeatPlayerIsSittingOn.Name))\t\t\nend, function(seatPlayerIsNoLongerSittingOn)\n\tif newSeatPlayerIsNoLongerSittingOn ~= nil then \n\t\tprint(player.Name .. \" left seat \" ..tostring(newSeatPlayerIsNoLongerSittingOn.Name))\t\t\n\tend\nend)\n```\n\nObserves the given `player`'s `humanoid.SeatPart`, but also accounting for cases where the `player`'s humanoid has not being\nloaded yet or if the `player`'s humanoid is updated (for e.g on character respawn).",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "observerSeated",
                    "desc": "",
                    "lua_type": "((\n\t\tseatPlayerIsSittingOn: Seat | VehicleSeat\n\t) -> ())?"
                },
                {
                    "name": "observerUnseated",
                    "desc": "",
                    "lua_type": "((\n\t\tseatPlayerIsNoLongerSittingOn: (Seat | VehicleSeat)?\n\t) -> ())?\n"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Connection"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 239,
                "path": "src/playerHumanoidUtil/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "playerHumanoidUtil",
    "desc": "A simple utility module for working with the player's humanoid.",
    "source": {
        "line": 6,
        "path": "src/playerHumanoidUtil/init.luau"
    }
}