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: (mouse.KeyDown/Up)/tick()

Previous Thread :: Next Thread 
ToboboT is not online. ToboboT
Joined: 25 Jun 2011
Total Posts: 2385
18 Dec 2013 04:14 PM
mouse.KeyDown:connect(function(key)
if key == "e" then
local start = tick()
mouse.KeyUp:connect(function(key2)
if key2 == "e" then
local finish = tick()
if (start - finish) > 3 then
mouse.Target.bon.Value = true
end
end
end)
end
end)

for some reason this doesn't work and well i don't know if it is something wrong with the tick() or the KeyUp KeyDown? no outputs
Report Abuse
ToboboT is not online. ToboboT
Joined: 25 Jun 2011
Total Posts: 2385
18 Dec 2013 04:43 PM
bunp
Report Abuse
ToboboT is not online. ToboboT
Joined: 25 Jun 2011
Total Posts: 2385
18 Dec 2013 06:35 PM
Bump
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
18 Dec 2013 06:39 PM
The system is flawed. That's what I cought at first sight.


mouse.KeyUp will stack because that line of code will be create again from mouse.KeyDown

Solution:
http://wiki.roblox.com/index.php/Debounce
http://wiki.roblox.com/index.php/Disconnect#Methods_2
Report Abuse
ToboboT is not online. ToboboT
Joined: 25 Jun 2011
Total Posts: 2385
18 Dec 2013 06:43 PM
i sortof read the wiki's but how could i use the disconnect in the existing script?
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
18 Dec 2013 06:48 PM
mouse.KeyDown:connect(function(key)
if key == "e" then
local start = tick()
local event
event = mouse.KeyUp:connect(function(key2)
if key2 == "e" then
local finish = tick()
if (start - finish) > 3 then
mouse.Target.bon.Value = true
end
event:disconnect()
end

end)
end
end)


-- This would disconnect KeyUp after KeyUp is activated and the key is e (regardless if (start - finish) > 3) ...
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
18 Dec 2013 06:49 PM
The solution is the wait() method of the RBXScriptSignal.
local function onKeyDown(key)
if key == "e" then
local start = tick()
repeat until mouse.KeyUp:wait() == "e"
local finish = tick()
end
end
mouse.KeyDown:connect(onKeyDown)
Report Abuse
ArbiterOfDeath is not online. ArbiterOfDeath
Joined: 20 Jun 2011
Total Posts: 1458
18 Dec 2013 06:51 PM
Oh, sorry and you wanted to print of the time elapsed. This is also much better then the code suggested above my posts. Here it is:

local function onKeyDown(key)
if key == "e" then
local start = tick()
repeat until mouse.KeyUp:wait() == "e"
print(tick() - start)
end
end

mouse.KeyDown:connect(onKeyDown)
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
18 Dec 2013 06:51 PM
His technique also work... and it's suggested by me since it's cleaner =P.
Report Abuse
ToboboT is not online. ToboboT
Joined: 25 Jun 2011
Total Posts: 2385
18 Dec 2013 06:54 PM
OH OK I didn't know there was a wait() thingy :o wow that is really useful
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