CharacterUtils
A set of utility functions for working with characters.
Functions
GetCharacter
CharacterUtils:GetCharacter(shouldYield: boolean?--
Whether or not to yield until the character exists (will still return nil if the player leaves the game)
) → Model?--
The character of the player if it exists
Get the character of a player and optionally yield until it exists
GetLocalCharacter
This item only works when running on the client. ClientCharacterUtils:GetLocalCharacter(shouldYield: boolean?--
Whether or not to yield until the character exists
) → Model?--
The character of the local player if it exists
Get the character of the local player and optionally yield until it exists
GetAllCharacters
Get all characters of players
GetAllNonLocalCharacters
This item only works when running on the client. ClientGet all characters of players
OnCharacterSpawned
CharacterUtils:OnCharacterSpawned(callback: function,--
The callback to run when the player spawns
callbackName: string,--
The name of the callback to add (optional)
priority: number?--
The priority of the callback, lower numbers run first (optional, defaults to 0)
) → ()Add a callback for when the player spawns and provide a maid for cleaning up any connections or running functions when the player dies.
This will run the callback immediately if the player is already spawned.
OnAnyCharacterSpawned
CharacterUtils:OnAnyCharacterSpawned(callbackName: string?,--
The name of the callback to add (optional)
priority: number?) → ()Adds a callback for any player, existing and future, that spawns.
OnLocalCharacterSpawned
This item only works when running on the client. ClientCharacterUtils:OnLocalCharacterSpawned(callback: function(character: Model,characterMaid: Maid) → (),--
The callback to run when the player spawns
callbackName: string?,--
The name of the callback to add (optional)
priority: number?) → ()Add a callback for when the local player spawns and provide a maid for cleaning up any connections or running functions when the player dies.
RemoveOnSpawnedCallback
CharacterUtils:RemoveOnSpawnedCallback(callbackName: string--
The name of the callback to remove
) → ()Remove a callback for when the player spawns
RemoveLocalOnSpawnedCallback
This item only works when running on the client. ClientCharacterUtils:RemoveLocalOnSpawnedCallback(callbackName: string--
The name of the callback to remove
) → ()Remove a callback for when the local player spawns
RemoveOnAnySpawnedCallback
CharacterUtils:RemoveOnAnySpawnedCallback(callbackName: string--
The name of the callback to remove
) → ()Remove a callback for all players when they spawn, future and existing
RemoveAllCallbacksForPlayer
CharacterUtils:RemoveAllCallbacksForPlayer() → ()Remove all callbacks for when the player spawns
RemoveAllLocalCallbacks
This item only works when running on the client. ClientCharacterUtils:RemoveAllLocalCallbacks() → ()Remove all callbacks for when the local player spawns
GetCharacterMaid
CharacterUtils:GetCharacterMaid() → table--
The CharacterMaid for the player
Get the maid for the player's character
GetLocalCharacterMaid
This item only works when running on the client. ClientCharacterUtils:GetLocalCharacterMaid() → table--
The CharacterMaid for the local player
Get the maid for the local player's character
GetChildFromCharacter
CharacterUtils:GetChildFromCharacter(childName: stringThenameofthechildtoget,shouldYield: boolean?) → Instance?InstanceThechildifitexistsRetrieves a child from a player's character
GetChildFromLocalCharacter
This item only works when running on the client. ClientCharacterUtils:GetChildFromLocalCharacter(childName: string,--
The name of the child to get
shouldYield: boolean?) → Instance?--
The child if it exists
Retrieves a child from the local player's character
PlayAnimationOnCharacter
CharacterUtils:PlayAnimationOnCharacter(character: Model | Player,--
The character to play the animation on (can pass a player to play the animation on their character)
animationId: string | number,--
The id of the animation to play, can be a string or number
animTrackOptions: table?,--
The options to pass to the animation track on play as well as whether or not to cache the animation track
shouldYield: boolean?--
Whether or not to yield until the character exists
) → AnimationTrack?--
The animation track if it was successfully played
Plays an animation on a character
PlayAnimationOnLocalCharacter
This item only works when running on the client. ClientCharacterUtils:PlayAnimationOnLocalCharacter(animationId: string | number,--
The id of the animation to play, can be a string or number
animTrackOptions: table?,--
The options to pass to the animation track on play as well as whether or not to cache the animation track
shouldYield: boolean?--
Whether or not to yield until the character exists
) → AnimationTrack?--
The animation track if it was successfully played
Plays an animation on the local player's character
Example:
local animationTrack = CharacterUtils:PlayAnimationOnLocalCharacter("rbxassetid://1234567890", {
fadeTime = 0.1,
weight = 1,
speed = 1,
shouldNotCache = false,
}, true)
GetCharacterFromPart
Gets the character from a part if one exists. Will also return NPCs.