Skip to main content

CharacterUtils

General character utility code.

Functions

getPlayerHumanoid

CharacterUtils.getPlayerHumanoid(playerPlayer) → Humanoid?--

Nil if not found

Gets a player's humanoid, if it exists

getAlivePlayerHumanoid

CharacterUtils.getAlivePlayerHumanoid(playerPlayer) → Humanoid?--

Nil if not found

Gets a player's humanoid, and ensures it is alive, otherwise returns nil

getAlivePlayerRootPart

CharacterUtils.getAlivePlayerRootPart(playerPlayer) → BasePart?--

Nil if not found

Gets a player's humanoid's rootPart, and ensures the humanoid is alive, otherwise returns nil

getPlayerRootPart

CharacterUtils.getPlayerRootPart(playerPlayer) → BasePart?--

Nil if not found

Gets a player's humanoid's rootPart otherwise returns nil

unequipTools

CharacterUtils.unequipTools(playerPlayer) → ()

Unequips all tools for a give player's humanomid, if the humanoid exists

local Players = game:GetService("Players")

for _, player in pairs(Players:GetPlayers()) do
	CharacterUtils.unequipTools(player)
end

getPlayerFromCharacter

CharacterUtils.getPlayerFromCharacter(
descendantInstance--

A child of the potential character.

) → Player?--

Nil if not found

Returns the player that a descendent is part of, if it is part of one.

script.Parent.Touched:Connect(function(inst)
	local player = CharacterUtils.getPlayerFromCharacter(inst)
	if player then
		-- activate button!
	end
end)
tip

This method is useful in a ton of different situations. For example, you can use it on classes bound to a humanoid, to determine the player. You can also use it to determine, upon touched events, if a part is part of a character.

Show raw api
{
    "functions": [
        {
            "name": "getPlayerHumanoid",
            "desc": "Gets a player's humanoid, if it exists",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "Nil if not found",
                    "lua_type": "Humanoid?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 15,
                "path": "src/characterutils/src/Shared/CharacterUtils.lua"
            }
        },
        {
            "name": "getAlivePlayerHumanoid",
            "desc": "Gets a player's humanoid, and ensures it is alive, otherwise returns nil",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "Nil if not found",
                    "lua_type": "Humanoid?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 29,
                "path": "src/characterutils/src/Shared/CharacterUtils.lua"
            }
        },
        {
            "name": "getAlivePlayerRootPart",
            "desc": "Gets a player's humanoid's rootPart, and ensures the humanoid is alive, otherwise\nreturns nil",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "Nil if not found",
                    "lua_type": "BasePart?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 44,
                "path": "src/characterutils/src/Shared/CharacterUtils.lua"
            }
        },
        {
            "name": "getPlayerRootPart",
            "desc": "Gets a player's humanoid's rootPart otherwise returns nil",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [
                {
                    "desc": "Nil if not found",
                    "lua_type": "BasePart?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 58,
                "path": "src/characterutils/src/Shared/CharacterUtils.lua"
            }
        },
        {
            "name": "unequipTools",
            "desc": "Unequips all tools for a give player's humanomid, if the humanoid\nexists\n\n```lua\nlocal Players = game:GetService(\"Players\")\n\nfor _, player in pairs(Players:GetPlayers()) do\n\tCharacterUtils.unequipTools(player)\nend\n```",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 81,
                "path": "src/characterutils/src/Shared/CharacterUtils.lua"
            }
        },
        {
            "name": "getPlayerFromCharacter",
            "desc": "Returns the player that a descendent is part of, if it is part of one.\n\n```lua\nscript.Parent.Touched:Connect(function(inst)\n\tlocal player = CharacterUtils.getPlayerFromCharacter(inst)\n\tif player then\n\t\t-- activate button!\n\tend\nend)\n```\n\n:::tip\nThis method is useful in a ton of different situations. For example, you can\nuse it on classes bound to a humanoid, to determine the player. You can also\nuse it to determine, upon touched events, if a part is part of a character.\n:::",
            "params": [
                {
                    "name": "descendant",
                    "desc": "A child of the potential character.",
                    "lua_type": "Instance"
                }
            ],
            "returns": [
                {
                    "desc": "Nil if not found",
                    "lua_type": "Player?"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 109,
                "path": "src/characterutils/src/Shared/CharacterUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "CharacterUtils",
    "desc": "General character utility code.",
    "source": {
        "line": 5,
        "path": "src/characterutils/src/Shared/CharacterUtils.lua"
    }
}