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

Activate

The Activate function simulates a click on a Tool. The Tool must be equipped for this function to work.

Tools will normally trigger the Tool/Activated 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 activated and print “Tool activated” 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:Activate()
end)

function toolActivated()
    print("Tool activated")
end

tool.Activated:Connect(toolActivated)

Returns

Return Type Summary

No return


Code Samples


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.