PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

Deactivate

The Deactivate event simulates the deactivation of a Tool. Tools will normally trigger the Tool/Deactivated event when the player releases the left mouse button, while the tool is equipped.

Returns

Return Type Summary

Code Samples


Tool:Deactivate

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.

local ContextActionService = game:GetService("ContextActionService")
local tool = script.Parent
 
-- Gives Handle within Tool a random BrickColor
local function toolDeactivated()
	tool.Handle.BrickColor = BrickColor.Random()
end
 
-- Deactivates the tool when any key is pressed down
local function keyPressed(actionName, actionInputState, actionInputObject)	
	if actionInputState == Enum.UserInputState.Begin then
		tool:Deactivate()
	end
end
 
tool.Deactivated:Connect(toolDeactivated)
ContextActionService:BindAction("deactivateTool", keyPressed, true, "x")