Help with a player needing to hold the mouse for a certain amount of time with a tool

Hi everyone! I hope you are all doing well. I’m currently trying to make a system where a player needs to hold down their mouse for a certain amount of time for something to happen. I tried making something to see if it would work but it still printed without the mouse being held down. I’m pretty new to coding and was wondering if someone could help me with this. Thanks!!!

Here is what I tried:

tool = script.Parent

tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		wait(1)
		print("Data saved")
	end)
end)

Here is a kind of hacky way to do it, I don’t know if this is the most efficient but it works.

script.Parent.Equipped:Connect(function(mouse)
	local start

	mouse.Button1Down:Connect(function()
		start = tick()
	end)

	mouse.Button1Up:Connect(function()
		if tick() >= start + 1 then
			print("You waited one second")
		end
	end)
end)
1 Like
local globalTick

mouse.Button1Down:Connect(function()
  local currentTick = tick()
  globalTick = currentTick

  task.wait(1)

  if currentTick == globalTick then
    print('data saved')
  end
end)

mouse.Button1Up:Connect(function()
  globalTick = nil
end)

This is how I do it, probably the best way