How to run different functions for left click? (hold click and click)

I’ve been trying to figure out how to run two different functions without them contradicting? I’m trying to run the holding left click function first and if its down for more than .1 sec, then run the hold click function, otherwise run the second function (click).
I tried implementing my double click tick check, but I just can’t figure out how to set it up.
If there are better methods than this, please enlighten me.
ty

basically trying to figure out how to check how long a bool had been held.

First off, you could get the mouse then detect when it’s held

For the left click

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
    --Yourcode
end)

and the right click would be mouse.Button2Down

This does not answer my question. Im also using a tool so those aren’t the correct events

You could put that in the tool.Equipped event.

Yes sir, but I’m not having problems with events. Please reread my post.

Oh, my bad.
Well you can just add a wait(0.1) then run the other function.

You could try checking if the player was clicking because if it’s a click then the mouse has gone down and back up in a short time

also deactivated is an event

1 Like

tick() function? (30 characters)

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()

local LongPress = false
local MouseUp = false
local TimePressed = 0

Mouse.Button1Down:Connect(function()
	while not MouseUp do
		wait(.5)
		TimePressed = TimePressed + .5
	end
	
	MouseUp = false
end)

Mouse.Button1Up:Connect(function()
	MouseUp = true
	
	if TimePressed >= 1 then
		LongPress = true
		-- do something on long press
	else
		LongPress = false
		-- do something on short press
	end
	
	print(LongPress)
end)
2 Likes
local Tool = script.Parent
local isUp = false

--[[ WARNING: FRANKENCODE IS PRESENT:

THIS IS ONLY A ROUGH DRAFT AS TO HOW YOU
WOULD ACCOMPLISH THIS CODE AND IT SHOULD
BE REFINED IN A SECURE MANNER ASAP --]]

Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		print("Click event started")
		wait(0.5)
		if not isUp then
		print("Held event registered")
	end)
	
	Mouse.Button1Up:Connect(function()
		isUp = true
		print("Click or held event ended")
	end)
end)
4 Likes

Chose this as solution because this similar to what I came up with prior to reading the post. Thank you all

1 Like