fireclickdetector

Triggers a ClickDetector as if it was clicked.

Syntax

fireclickdetector(detector: ClickDetector, distance?: number, event?: string) -> ()

Parameters

ParameterTypeDescription
detectorClickDetectorThe ClickDetector to fire
distancenumber?The simulated click distance (default: 0)
eventstring?Event type: "MouseClick", "RightMouseClick", or "MouseHoverEnter/Leave"

Returns

This function does not return a value.

Description

fireclickdetector simulates a click on a ClickDetector, triggering its events without needing to be in range or actually clicking.

Example

local part = Instance.new("Part")
part.Parent = workspace

local detector = Instance.new("ClickDetector")
detector.Parent = part

-- Fire it
fireclickdetector(detector)

-- Fire with distance
fireclickdetector(detector, 10)

-- Fire right click
fireclickdetector(detector, 0, "RightMouseClick")

part:Destroy()

Finding and Clicking All

-- Click all ClickDetectors in a model
local function clickAll(parent)
    for _, desc in ipairs(parent:GetDescendants()) do
        if desc:IsA("ClickDetector") then
            fireclickdetector(desc)
        end
    end
end

-- Supply the container whose ClickDetectors you intend to activate
clickAll(workspace)

Notes

  • Omitted distance defaults to 0
  • Events: "MouseClick" (default), "RightMouseClick", "MouseHoverEnter", "MouseHoverLeave"