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
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)
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.