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 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)
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)