Skip to main content

toolUtil

A simple utility module for working with tools.

Functions

toolOwner

toolUtil.toolOwner(toolTool) → Player?

Attempts to returns the owner of the given tool, if found.

tryPlaceToolInBackpackAndStarterGear

toolUtil.tryPlaceToolInBackpackAndStarterGear(
playerPlayer,
toolTool
) → ()

Places the given tool in the given player's backpack and a cloned variant of it in player.StarterGear.

tryPlaceToolInBackpackAndEquip

toolUtil.tryPlaceToolInBackpackAndEquip(
playerPlayer,
toolTool
) → ()

Places the given tool in the given player's backpack and tries to equips it on the humanoid.

mappedPlayerToolCount

toolUtil.mappedPlayerToolCount(
playerPlayer,
predicate(toolTool) → boolean
) → ()

Returns the player tool count. predicate is called on every tool owned by the given player, and each time it returns true, the tool count is incremented by 1.

playerTools

toolUtil.playerTools(playerPlayer) → ()

Returns a read only array of all player tools - both equipped and unequipped.

currentEquippedTool

toolUtil.currentEquippedTool(playerPlayer) → ()

Returns the current equipped tool by the player.

observePlayerForToolsEquippedAndUnequipped

toolUtil.observePlayerForToolsEquippedAndUnequipped(
playerPlayer,
observerForToolEquipped((toolEquippedTool) → ())?,
observerForToolUnequipped((toolUnequippedTool) → ())?
) → ()

Observes the player for any new tools equipped or unequipped. Also captures all the initial tool equipped.

toolUtil.observePlayerForEquippedTool(player, function(newToolEquipped)

end, function(newToolUnequipped)

end)
WARNING

This method will throw an error if both observerForToolEquipped and observerForToolUnequipped are not specified, at least any one of them must be specified.

observePlayerBackpackForTools

toolUtil.observePlayerBackpackForTools(
playerPlayer,
observerForToolAdded((newToolAddedTool) → ())?,
observerForToolRemoved((newToolRemovedTool) → ())?
) → ()

Observes the player's backpack for any new tools added or removed. Also captures all initial tools in the player backpack.

toolUtil.observePlayerBackpackForTools(player, function(toolAdded)

end, function(toolRemoved)

end)
WARNING

This method will throw an error if both observerForToolAdded and observerForToolRemoved are not specified, at least any one of them must be specified.

observePlayerForToolOwnership

toolUtil.observePlayerForToolOwnership(
playerPlayer,
observerForToolOwnershipGranted((newToolTool) → ())?,
observerForToolOwnershipRemoved((newToolTool) → ())?
) → ()

Observes the player's backpack and character for any new tools added or removed.

toolUtil.observePlayerForToolOwnership(player, function(toolOwnershipGranted)

end, function(toolOwnershipRemoved)

end)
WARNING

This method will throw an error if both observerForToolOwnershipGranted and observerForToolOwnershipRemoved are not specified, at least any one of them must be specified.

Show raw api
{
    "functions": [
        {
            "name": "toolOwner",
            "desc": "Attempts to returns the owner of the given tool, if found.",
            "params": [
                {
                    "name": "tool",
                    "desc": "",
                    "lua_type": "Tool"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Player?\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 43,
                "path": "src/toolUtil/init.luau"
            }
        },
        {
            "name": "tryPlaceToolInBackpackAndStarterGear",
            "desc": " \nPlaces the given tool in the given `player`'s backpack and a cloned variant of it in `player.StarterGear`.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "tool",
                    "desc": "",
                    "lua_type": "Tool"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 62,
                "path": "src/toolUtil/init.luau"
            }
        },
        {
            "name": "tryPlaceToolInBackpackAndEquip",
            "desc": " \nPlaces the given tool in the given `player`'s backpack and tries to equips it on the humanoid.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "tool",
                    "desc": "",
                    "lua_type": "Tool"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 71,
                "path": "src/toolUtil/init.luau"
            }
        },
        {
            "name": "mappedPlayerToolCount",
            "desc": "Returns the player tool count. `predicate` is called on every tool owned by the given `player`, and each time it returns `true`, \nthe tool count is incremented by 1.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "predicate",
                    "desc": "",
                    "lua_type": "(tool: Tool) -> boolean"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 88,
                "path": "src/toolUtil/init.luau"
            }
        },
        {
            "name": "playerTools",
            "desc": "Returns a read only array of all player tools - both equipped and unequipped.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 103,
                "path": "src/toolUtil/init.luau"
            }
        },
        {
            "name": "currentEquippedTool",
            "desc": " \nReturns the current equipped tool by the player.",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 121,
                "path": "src/toolUtil/init.luau"
            }
        },
        {
            "name": "observePlayerForToolsEquippedAndUnequipped",
            "desc": " \nObserves the player for any new tools equipped or unequipped. Also captures\nall the initial tool equipped. \n\n```lua\ntoolUtil.observePlayerForEquippedTool(player, function(newToolEquipped)\n\nend, function(newToolUnequipped)\n\nend)\n```\n\n:::warning\nThis method will throw an error if both `observerForToolEquipped` and `observerForToolUnequipped` are not specified, at least any *one* of them must be specified.\n:::",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "observerForToolEquipped",
                    "desc": "",
                    "lua_type": "((toolEquipped: Tool) -> ())?"
                },
                {
                    "name": "observerForToolUnequipped",
                    "desc": "",
                    "lua_type": "((toolUnequipped: Tool) -> ())?\n"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 142,
                "path": "src/toolUtil/init.luau"
            }
        },
        {
            "name": "observePlayerBackpackForTools",
            "desc": " \nObserves the player's backpack for any new tools added or removed. Also captures\nall initial tools in the player backpack.\n\n```lua\ntoolUtil.observePlayerBackpackForTools(player, function(toolAdded)\n\nend, function(toolRemoved)\n\nend)\n```\n\n:::warning\nThis method will throw an error if both `observerForToolAdded` and `observerForToolRemoved` are not specified, at least any *one* of them must be specified.\n:::",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "observerForToolAdded",
                    "desc": "",
                    "lua_type": "((newToolAdded: Tool) -> ())?"
                },
                {
                    "name": "observerForToolRemoved",
                    "desc": "",
                    "lua_type": "((newToolRemoved: Tool) -> ())?\n"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 214,
                "path": "src/toolUtil/init.luau"
            }
        },
        {
            "name": "observePlayerForToolOwnership",
            "desc": " \nObserves the player's backpack and character for any new tools added or removed.\n\n```lua\ntoolUtil.observePlayerForToolOwnership(player, function(toolOwnershipGranted)\n\nend, function(toolOwnershipRemoved)\n\nend)\n```\n\n:::warning\nThis method will throw an error if both `observerForToolOwnershipGranted` and `observerForToolOwnershipRemoved` are not specified, at least any\n*one* of them must be specified.\n:::",
            "params": [
                {
                    "name": "player",
                    "desc": "",
                    "lua_type": "Player"
                },
                {
                    "name": "observerForToolOwnershipGranted",
                    "desc": "",
                    "lua_type": "((newTool: Tool) -> ())?"
                },
                {
                    "name": "observerForToolOwnershipRemoved",
                    "desc": "",
                    "lua_type": "((newTool: Tool) -> ())?\n"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 277,
                "path": "src/toolUtil/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "toolUtil",
    "desc": "A simple utility module for working with tools.",
    "source": {
        "line": 6,
        "path": "src/toolUtil/init.luau"
    }
}