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
 

Timer

Previous Thread :: Next Thread 
Saodo is not online. 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 is not online. 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 is not online. 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 is not online. Saodo
Joined: 26 Jul 2011
Total Posts: 1206
26 Apr 2014 12:15 PM
thank you :)
Report Abuse
Saodo is not online. 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 is not online. 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 is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
26 Apr 2014 12:29 PM
_G.time = tick() - t_start
Report Abuse
Saodo is not online. 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 is not online. 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
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