Saodo
|
  |
| Joined: 26 Jul 2011 |
| Total Posts: 1206 |
|
|
| 26 Apr 2014 12:04 PM |
How do i create a timer that starts when a brick is touched and stops when another brick is touched?
When the finish brick is touched the time should display in the output window.
|
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 26 Apr 2014 12:10 PM |
start_brick = Workspace.?? end_brick = Workspace.??
stop = false time = nil
start_brick.Touched:connect(function(hit) local hum = hit.Parent:FindFirstChild("Humanoid") local t_start if hum ~= nil then local tmp t_start = tick() repeat tmp = end_brick.Touched:wait() until tmp.Parent:FindFirstChild("Humanoid")~= nil time = tick() - t_start print(time) end end)
|
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 26 Apr 2014 12:12 PM |
let me add a debounce real quick:
start_brick = Workspace.?? end_brick = Workspace.??
stop = false time = nil debounce = false
start_brick.Touched:connect(function(hit) if debounce then return end local hum = hit.Parent:FindFirstChild("Humanoid") local t_start if hum ~= nil then debounce = true local tmp t_start = tick() repeat tmp = end_brick.Touched:wait() until tmp.Parent:FindFirstChild("Humanoid")~= nil time = tick() - t_start print(time) end end)
There. |
|
|
| Report Abuse |
|
|
Saodo
|
  |
| Joined: 26 Jul 2011 |
| Total Posts: 1206 |
|
| |
|
Saodo
|
  |
| Joined: 26 Jul 2011 |
| Total Posts: 1206 |
|
|
| 26 Apr 2014 12:17 PM |
| Can you make the final time a global variable so i can use it in other scripts? |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 26 Apr 2014 12:28 PM |
Yeah, sure, just change the line
_G.time = tick() - t |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 26 Apr 2014 12:29 PM |
| _G.time = tick() - t_start |
|
|
| Report Abuse |
|
|
Saodo
|
  |
| Joined: 26 Jul 2011 |
| Total Posts: 1206 |
|
|
| 26 Apr 2014 12:31 PM |
| The time seems a bit quick when comparing it to the result when i count in my head. Does a tick function work differently ? |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 26 Apr 2014 12:34 PM |
| tick is pretty much as accurate you can get when dealing with time |
|
|
| Report Abuse |
|
|