playerHumanoidUtil
A simple utility module for working with the player's humanoid.
Functions
playerHumanoid
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
Promisfied verison of playerHumanoidUtil.playerHumanoid.
Automatic promise cancellation
The returned promise will be cancelled automatically once player
is no longer in game!
trySeatPlayerPromise
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 anOccupant
which is not theplayer
'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
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 anOccupant
which is not theplayer
'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(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).