How to detect double click on UserInputService?

Is there any way to detect the person double clicking using user input service? Like a way to detect if the person quickly presses click say, Click 2 times in 1 second and it will fire a server event, but if you don’t then it fires another server event.

1 Like

Why not just use the tick() function subtract the new time from the time of the last click and if its below a certain time then fire a double click event.

This should help you some more if your confused

6 Likes

Will do, thanks! (30charactersbruh)

So, I was poking around on the internet and I couldn’t find a good solution for this. So, I made one of my own:

Edit (Apr 29): Added more customization :slight_smile:

local button = script.Parent -- or wherever your button is
local count = 0 -- initial count, should always be 0
local threshHold = 2 -- you can set this to even 3 of 4 to get triple and quadriple clicks!
local clickTime = 0.5 -- the time within the clicks should be clicked

function onClick ()
	count += 1 -- add 1 to the number of clicks
	
	if count % threshHold == 0 then -- you reached the threshold
		print("multi click accepted!") -- replace with your code
	end
	
	wait(clickTime) -- just wait to invalidate the click
	count -= 1 -- invalidate the click
end
button.MouseButton1Click:Connect(onClick)
button.TouchTap:Connect(onClick) -- yes, it even works for touch screen!
31 Likes

thank you for providing a different, and more useful solution as opposed to just using :tick(), by making it have touchscreen compatibility!

2 Likes

I made a mistake in the code, so please use the new one :smile:

1 Like