How would I detect a double click correctly?

Here’s a ‘UserInputService’ implementation that detects ‘double’ clicks, porting it to a tool’s ‘Activated’ signal should be simple enough.

local Enumeration = Enum
local Game = game
local RunService = Game:GetService("RunService")
local UserInputService = Game:GetService("UserInputService")

local LastClickTime = 0
local DoubleClickTime = 0.15 --Maximum time in seconds for two consecutive clicks to be considered a 'double' click.

local function OnInputBegan(InputObject, GameProcessed)
	if GameProcessed then return end
	if InputObject.UserInputType ~= Enumeration.UserInputType.MouseButton1 then return end
	local CurrentClickTime = RunService.Stepped:Wait()
	if (CurrentClickTime - LastClickTime) < DoubleClickTime then
		print("Double click!")
	end
	LastClickTime = CurrentClickTime
end

UserInputService.InputBegan:Connect(OnInputBegan)
3 Likes