PcoWSkbVqDnWTu_dm2ix
The Developer Hub is now deprecated and information on this page may no longer be accurate. To see our new and improved documentation, please click here. You can read more about the future of documentation here.
Collapse Sidebar

Deactivate

The Deactivate function simulates the deactivation of a Tool. The Tool must be equipped for this function to work.

Tools will normally trigger the Tool/Deactivated event when the player releases the left mouse button, while the tool is equipped.

The below code, when placed in a LocalScript, would create a tool in the Players/LocalPlayer|LocalPlayer's Backpack. It will simulate the tool being deactivated and print “Tool deactivated” when the player equips the tool.

local tool = Instance.new("Tool")
tool.RequiresHandle = false
tool.Parent = game.Players.LocalPlayer.Backpack

tool.Equipped:Connect(function()
	tool:Deactivate()
end)

function toolDeactivated()
    print("Tool deactivated")
end

tool.Deactivated:Connect(toolDeactivated)

Returns

Return Type Summary

No return


Code Samples


Change Tool Color on Key Press

The below code is intended to be inserted into a script within a Tool. The script will deactivate the tool when the user presses the x key, while the tool is equipped. The script also changes the handle’s color when the tool is deactivated.


Invisibility Tool

The code below creates a tool in the Players/LocalPlayer|LocalPlayer's Backpack that turns the player invisible when activated and visible when deactivated.

When equipped, the script simulates the tool being activated and turns the player invisible for 3 seconds and then simulates the tool being deactivated. Holding the left mouse button down turns the player invisible for up to 3 seconds, with a cooldown period of 1 second, or until the player releases their left mouse button.