Advertisement
Guest User

Timer GUI Localscript Roblox Studio

a guest
Jan 23rd, 2021
1,131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. --[[
  2. Layout:
  3. TimerGui
  4.  - Frame
  5.   -Localscript
  6.   -StartTimer
  7.   -EndTimer
  8.   -TextLabel
  9.  
  10. StartTimer and EndTimer are BindableEvents
  11. ]]--
  12. local startTimer = script.Parent.StartTimer
  13. local endTimer = script.Parent.EndTimer
  14. local gui = script.Parent
  15. local text = script.Parent.TextLabel
  16.  
  17. local function timeToString(seconds)
  18.     local minutes = math.floor(seconds / 60)
  19.     local seconds = tostring(math.floor(seconds - (minutes * 60))
  20.     )
  21.     minutes = tostring(minutes)
  22.     if string.len(minutes) == 1 then
  23.         minutes = "0"..minutes
  24.     end
  25.    
  26.     if string.len(seconds) == 1 then
  27.         seconds = "0"..seconds
  28.     end
  29.    
  30.     return minutes..":"..seconds
  31.    
  32. end
  33. startTimer.Event:Connect(function(seconds)
  34.     gui.Visible = true
  35.    
  36.     local startTime = os.clock()
  37.     while os.clock() - startTime < seconds  do
  38.         text.Text = timeToString(seconds - (os.clock() - startTime))
  39.         wait()
  40.     end
  41.    
  42.     endTimer:Fire()
  43.     gui.Visible = false
  44.    
  45. end)
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement