So I already have functions made for when a key is pressed, but I am unsure of how to get the number of seconds a key is held down. In other words, I need something to happen only after holding a key down for a certain number of seconds. Any help would be appreciated. Thanks in advanced.
✓ ANSWER ACCEPTED
How Would You Get the Time a Key is Held Down?
1 answer
✓ Accepted answer
We need to save the time when the key is pressed down and compare it to when it is lifted.
im using the function time() which gives us the number of second after the server started
local lastTime=0
keydown.Connect(function()
lastTime=time()
end)
keyup.Connect(function()
local dif=time()-lastTime
end)
Edit
local lastTime=0
local down=false
keydown.Connect(function()
lastTime=time()
down=true
while down do
print(time()-lastTime)
wait(1)
end
end)
keyup.Connect(function()
down=false
local dif=time()-lastTime
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
How would you go about printing something to output for each second it is held down?
print(dif)
@corncob567 updated answer