Advertisement
B_Ricey

Roblox Timer/Clock Script

Feb 27th, 2021
6,598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2.  
  3. local TIMER_BINDING_NAME = "Timer"
  4.  
  5. local label = script.Parent
  6.  
  7. local function startTimer(timeLeft)
  8.     local delayEvent = Instance.new("BindableEvent")
  9.    
  10.     RunService:BindToRenderStep(TIMER_BINDING_NAME, Enum.RenderPriority.Last.Value - 1, function(delta)
  11.         -- delta is the time since the last frame
  12.         -- 01:30:01
  13.         timeLeft -= delta
  14.        
  15.         local minutes = math.floor(timeLeft / 60)
  16.         local seconds = math.floor(timeLeft % 60)
  17.         local hundreths = math.floor(timeLeft % 1 * 100)
  18.            
  19.         label.Text = string.format("%02i:%02i:%02i", minutes, seconds, hundreths)
  20.        
  21.         if timeLeft <= 0 then
  22.             delayEvent:Fire()
  23.             RunService:UnbindFromRenderStep(TIMER_BINDING_NAME)
  24.         end
  25.        
  26.     end)
  27.    
  28.     delayEvent.Event:Wait()
  29. end
  30.  
  31. startTimer(10)
  32. label.Text = "Done"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement