generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How to detect if a key is double tapped?

Previous Thread :: Next Thread 
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 04:57 PM
I thought about doing a check after .5 seconds to see if it has been pressed twice, but I'm sure there is a shorter way.
Perhaps involving 'tick()'

What I have:

local m = game.Players.LocalPlayer:GetMouse();
local pressed = 0;
local variable = false;

m.KeyDown:connect(function(key)
pressed = pressed +1
variable = true
end
end)

while wait() do
if variable == true then
wait(.5)
if pressed >= 2 then
--do stuff
end
end
end

I'm 99.99% sure there is a shorter way, and I'm not even sure if the way I'm doing it right now will work.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 05:00 PM
I checked out the wiki.
So is this how I would do it?

tapped = tick()

if tick() - tapped <= .5 and > 0 then
--do stuff
end
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 05:01 PM
Except tapped would be defined when the key is pressed. And then it resets after .5 seconds.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 05:20 PM
I fixed some corrections on what I had now.

m.KeyDown:connect(function(k)
if (k:lower()) == " w" then
if tick() - sprint.SprintTap <= .5 and tick()-sprint.SprintTap > 0 then
if anim == false and sprint.sprintVar == false and sprint.extra == false then
anim = true sprint.sprintVar = true sprint.extra = true
sprint()
end
end
end
end)
m.KeyUp:connect(function(k)
if (k:lower()) == "q" then
if anim == true and sprint.sprintVar == true and sprint.extra == true then
unsprint()
anim = false sprint.sprintVar = false sprint.extra = false
end
end
end)

This is what I currently have, and it isn't working. I think it may have something to do with the tick() stuff.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 05:22 PM
Ok, so now I'm sure the problem is because it isn't detecting if it is being double tapped.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 05:26 PM
Is it really that hard?
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 05:32 PM
Bump.
Report Abuse
IAmTheRolo is online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
12 May 2014 05:33 PM
I recommend reading through this (not mine):

http://www.roblox.com/Re-How-to-detect-if-someone-double-clicks-item?id=138249187

It helped me, at least.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 05:46 PM
Not working.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 06:19 PM
Now I have this. Still won't work:

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(k)
if (k:lower()) == 'w' and anim == false and sprint.sprintVar == false then
if (tick() - sprint.SprintTap) <= .5 and (tick() - sprint.SprintTap > 0) then
anim = true
sprint()
sprint.sprintVar = true
else
sprint.SprintTap = tick()
end
game.Players.LocalPlayer:GetMouse().KeyUp:connect(function(k)
if (k:lower()) == 'w' and anim == true and sprint.sprintVar == true then
sprint.sprintVar = false
unsprint()
anim = false
end
end)
end
end)
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
12 May 2014 06:22 PM
Bump.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image