Skip to main content

CharacterStateHandler

This item only works when running on the client. Client

Handles the replication and management of character states from the StateManager to the client. This class monitors character movement, grounding, and orientation to determine the current player activity state.

Types

PlayerState

type PlayerState = "Idle" | "Walk" | "Run" | "Jump" | "Fall"

Represents the possible activity states for a player character.

CharacterStateHandlerType

interface CharacterStateHandlerType {
CharacterModel--

The physical character model associated with this handler.

CurrentStatePlayerState--

The current activity state of the player (e.g., "Idle", "Walk").

MovingDirectionVector3--

The direction the character is currently moving toward.

FacingDirectionVector3--

The direction the character is currently facing.

VelocityVector3--

The current velocity vector of the character.

IsGroundedboolean--

Whether the character is currently touching the ground.

_init(selfany) → ()--

Internal initialization routine for the handler.

_updateState(
selfany,
deltaTimenumber
) → ()--

Internal logic for calculating and transitioning between states.

GetCurrentState(selfany) → PlayerState--

Returns the current active state of the character.

new(characterModel) → CharacterStateHandlerType--

Constructor for creating a new CharacterStateHandler instance.

}

Defines the structure and methods for managing the physical and logical state of a character.

Functions

new

CharacterStateHandler.new(
characterModel--

The character model to manage.

) → CharacterStateHandlerType--

The handler instance.

Creates a new CharacterStateHandler for the given character model. If a handler already exists for the character in the cache, it returns the cached instance.

getInstanceCache

CharacterStateHandler.getInstanceCache() → {[Model]CharacterStateHandlerType}

Returns the internal cache of all active CharacterStateHandler instances.

GetCurrentState

CharacterStateHandler:GetCurrentState() → PlayerState--

The current state (Idle, Walk, Run, etc).

Returns the current active state of the character.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new CharacterStateHandler for the given character model. \nIf a handler already exists for the character in the cache, it returns the cached instance.",
            "params": [
                {
                    "name": "character",
                    "desc": "The character model to manage.",
                    "lua_type": "Model"
                }
            ],
            "returns": [
                {
                    "desc": "The handler instance.",
                    "lua_type": "CharacterStateHandlerType"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 67,
                "path": "global/ReplicatedStorage/Scripts/Modules/CharacterStateHandler.luau"
            }
        },
        {
            "name": "_init",
            "desc": "Initializes the handler by connecting to physics updates and setting up \nreferences to the ControllerManager and HumanoidRootPart.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 89,
                "path": "global/ReplicatedStorage/Scripts/Modules/CharacterStateHandler.luau"
            }
        },
        {
            "name": "_updateState",
            "desc": "Calculates the current state of the character based on velocity, grounding, \nand movement input.",
            "params": [
                {
                    "name": "deltaTime",
                    "desc": "The time elapsed since the last update.",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 112,
                "path": "global/ReplicatedStorage/Scripts/Modules/CharacterStateHandler.luau"
            }
        },
        {
            "name": "getInstanceCache",
            "desc": "Returns the internal cache of all active CharacterStateHandler instances.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{[Model]: CharacterStateHandlerType}"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 148,
                "path": "global/ReplicatedStorage/Scripts/Modules/CharacterStateHandler.luau"
            }
        },
        {
            "name": "GetCurrentState",
            "desc": "Returns the current active state of the character.",
            "params": [],
            "returns": [
                {
                    "desc": "The current state (Idle, Walk, Run, etc).",
                    "lua_type": "PlayerState"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 156,
                "path": "global/ReplicatedStorage/Scripts/Modules/CharacterStateHandler.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "PlayerState",
            "desc": "Represents the possible activity states for a player character.",
            "lua_type": "\"Idle\" | \"Walk\" | \"Run\" | \"Jump\" | \"Fall\"",
            "source": {
                "line": 27,
                "path": "global/ReplicatedStorage/Scripts/Modules/CharacterStateHandler.luau"
            }
        },
        {
            "name": "CharacterStateHandlerType",
            "desc": "Defines the structure and methods for managing the physical and logical state of a character.",
            "fields": [
                {
                    "name": "Character",
                    "lua_type": "Model",
                    "desc": "The physical character model associated with this handler."
                },
                {
                    "name": "CurrentState",
                    "lua_type": "PlayerState",
                    "desc": "The current activity state of the player (e.g., \"Idle\", \"Walk\")."
                },
                {
                    "name": "MovingDirection",
                    "lua_type": "Vector3",
                    "desc": "The direction the character is currently moving toward."
                },
                {
                    "name": "FacingDirection",
                    "lua_type": "Vector3",
                    "desc": "The direction the character is currently facing."
                },
                {
                    "name": "Velocity",
                    "lua_type": "Vector3",
                    "desc": "The current velocity vector of the character."
                },
                {
                    "name": "IsGrounded",
                    "lua_type": "boolean",
                    "desc": "Whether the character is currently touching the ground."
                },
                {
                    "name": "_init",
                    "lua_type": "(self: any) -> ()",
                    "desc": "Internal initialization routine for the handler."
                },
                {
                    "name": "_updateState",
                    "lua_type": "(self: any, deltaTime: number) -> ()",
                    "desc": "Internal logic for calculating and transitioning between states."
                },
                {
                    "name": "GetCurrentState",
                    "lua_type": "(self: any) -> PlayerState",
                    "desc": "Returns the current active state of the character."
                },
                {
                    "name": "new",
                    "lua_type": "(character: Model) -> CharacterStateHandlerType",
                    "desc": "Constructor for creating a new CharacterStateHandler instance."
                }
            ],
            "source": {
                "line": 44,
                "path": "global/ReplicatedStorage/Scripts/Modules/CharacterStateHandler.luau"
            }
        }
    ],
    "name": "CharacterStateHandler",
    "desc": "Handles the replication and management of character states from the StateManager to the client. \nThis class monitors character movement, grounding, and orientation to determine the current \nplayer activity state.",
    "realm": [
        "Client"
    ],
    "source": {
        "line": 11,
        "path": "global/ReplicatedStorage/Scripts/Modules/CharacterStateHandler.luau"
    }
}