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
|
  |
| Joined: 25 Jun 2011 |
| Total Posts: 2385 |
|
| |
|
ToboboT
|
  |
| Joined: 25 Jun 2011 |
| Total Posts: 2385 |
|
| |
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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 |
|
|