Advertisement
XZTablets

Timer GUI

Aug 28th, 2020 (edited)
4,494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.94 KB | None | 0 0
  1. if not game:IsLoaded() then
  2.     game.Loaded:Wait()
  3. end
  4.  
  5. local Player = game:GetService("Players").LocalPlayer
  6. local Mouse = Player:GetMouse()
  7. local TweenService, TextService, RunService, StatService = game:GetService("TweenService"), game:GetService("TextService"), game:GetService("RunService"), game:GetService("Stats")
  8. local TargetParent = RunService:IsStudio() and Player.PlayerGui or game:GetService("CoreGui")
  9.  
  10. return function(Settings)
  11.     local Settings = (typeof(Settings) == "table") and Settings or {
  12.         ScriptName = "Utilities",
  13.         Timer = true,
  14.         FPS = true,
  15.         Decimals = 0,
  16.         CacheSize = 10,
  17.         Center = true
  18.     }
  19.  
  20.     Settings.ScriptName = Settings.ScriptName or "Utilities"
  21.     Settings.Timer = (typeof(Settings.Timer) == "boolean") and Settings.Timer or false
  22.     Settings.FPS = (typeof(Settings.FPS) == "boolean") and Settings.FPS or false
  23.     Settings.Decimals = Settings.Decimals or 0
  24.     Settings.CacheSize = Settings.CacheSize or 10
  25.     Settings.Center = (typeof(Settings.Center) == "boolean") and Settings.Center or false
  26.  
  27.     local OldInstance = TargetParent:FindFirstChild(Settings.ScriptName)
  28.     pcall(function() OldInstance:Destroy() end)
  29.  
  30.     local NewInstance = Instance.new("ScreenGui")
  31.     NewInstance.Name = Settings.ScriptName
  32.     NewInstance.Parent = TargetParent
  33.  
  34.     local Container = Instance.new("Frame")
  35.     Container.Name = "Container"
  36.     Container.BackgroundTransparency = 1
  37.     Container.Size = UDim2.fromScale(0,0) + UDim2.fromOffset(0,22)
  38.     Container.Position = (Settings.Center) and UDim2.new(0.5, 0, 0, -26) or UDim2.new(1, 0, 0, -26)
  39.     Container.Parent = NewInstance
  40.  
  41.     local List = Instance.new("UIListLayout")
  42.     List.FillDirection = Enum.FillDirection[Settings.Center and "Vertical" or "Horizontal"]
  43.     List.HorizontalAlignment = Enum.HorizontalAlignment.Right
  44.     List.SortOrder = Enum.SortOrder.Name
  45.     List.Padding = UDim.new(0,4)
  46.     List.Parent = Container
  47.  
  48.     local function AlignContainer()
  49.         local ACS = List.AbsoluteContentSize
  50.         local CSX = ACS.X
  51.         Container.Size = UDim2.fromOffset(CSX, 22)
  52.         Container.Position = (Settings.Center) and UDim2.new(0.5, 0, 0, -26) or UDim2.new(1, -(CSX + 55), 0, -26)
  53.     end
  54.  
  55.     List:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(AlignContainer)
  56.  
  57.     if Settings.Timer then
  58.         local Timer = Instance.new("Frame")
  59.         Timer.Name = Settings.Center and "1" or "2"
  60.         Timer.BorderSizePixel = 0
  61.         Timer.BackgroundColor3 = Color3.fromRGB(30,30,30)
  62.         Timer.Size = UDim2.fromOffset(123,22)
  63.         Timer.Parent = Container
  64.        
  65.         local TimerList = Instance.new("UIListLayout")
  66.         TimerList.FillDirection = Enum.FillDirection.Horizontal
  67.         TimerList.Padding = UDim.new(0,1)
  68.         TimerList.VerticalAlignment = Enum.VerticalAlignment.Center
  69.         TimerList.Parent = Timer
  70.        
  71.         local Hours = Instance.new("Frame")
  72.         Hours.Name = "Hours"
  73.         Hours.Size = UDim2.fromScale(0,1) + UDim2.fromOffset(40,-2)
  74.         Hours.BackgroundColor3 = Color3.fromRGB(40,40,40)
  75.         Hours.BorderSizePixel = 0
  76.         Hours.ClipsDescendants = true
  77.         Hours.Parent = Timer
  78.        
  79.         local Minutes = Instance.new("Frame")
  80.         Minutes.Name = "Minutes"
  81.         Minutes.Size = UDim2.fromScale(0,1) + UDim2.fromOffset(40,-2)
  82.         Minutes.BackgroundColor3 = Color3.fromRGB(40,40,40)
  83.         Minutes.BorderSizePixel = 0
  84.         Minutes.ClipsDescendants = true
  85.         Minutes.Parent = Timer
  86.        
  87.         local Seconds = Instance.new("Frame")
  88.         Seconds.Name = "Seconds"
  89.         Seconds.Size = UDim2.fromScale(0,1) + UDim2.fromOffset(40,-2)
  90.         Seconds.BackgroundColor3 = Color3.fromRGB(40,40,40)
  91.         Seconds.BorderSizePixel = 0
  92.         Seconds.ClipsDescendants = true
  93.         Seconds.Parent = Timer
  94.        
  95.         local OldHour, OldMinute, OldSecond = 0, 0, 0
  96.        
  97.         local NewHour = Instance.new("TextLabel")
  98.         NewHour.Name = "Old"
  99.         NewHour.Text = OldHour
  100.         NewHour.Size = UDim2.fromScale(1,1)
  101.         NewHour.Font = Enum.Font.Gotham
  102.         NewHour.TextColor3 = Color3.fromRGB(255,255,255)
  103.         NewHour.TextSize = 12
  104.         NewHour.BackgroundTransparency = 1
  105.         NewHour.Parent = Hours
  106.        
  107.         local NewMinute = Instance.new("TextLabel")
  108.         NewMinute.Name = "Old"
  109.         NewMinute.Text = OldMinute
  110.         NewMinute.Size = UDim2.fromScale(1,1)
  111.         NewMinute.Font = Enum.Font.Gotham
  112.         NewMinute.TextColor3 = Color3.fromRGB(255,255,255)
  113.         NewMinute.TextSize = 12
  114.         NewMinute.BackgroundTransparency = 1
  115.         NewMinute.Parent = Minutes
  116.        
  117.         local NewSecond = Instance.new("TextLabel")
  118.         NewSecond.Name = "Old"
  119.         NewSecond.Text = OldSecond
  120.         NewSecond.Size = UDim2.fromScale(1,1)
  121.         NewSecond.Font = Enum.Font.Gotham
  122.         NewSecond.TextColor3 = Color3.fromRGB(255,255,255)
  123.         NewSecond.TextSize = 12
  124.         NewSecond.BackgroundTransparency = 1
  125.         NewSecond.Parent = Seconds
  126.  
  127.         local function ClearAll()
  128.             for _, Object in ipairs(Hours:GetChildren()) do
  129.                 if (NewHour) and (not (Object == NewHour)) then
  130.                     Object:Destroy();
  131.                 end
  132.             end
  133.  
  134.             for _, Object in ipairs(Minutes:GetChildren()) do
  135.                 if (NewMinute) and (not (Object == NewMinute)) then
  136.                     Object:Destroy();
  137.                 end
  138.             end
  139.  
  140.             for _, Object in ipairs(Seconds:GetChildren()) do
  141.                 if (NewSecond) and (not (Object == NewSecond)) then
  142.                     Object:Destroy();
  143.                 end
  144.             end
  145.         end
  146.        
  147.         local function UpdateTime()
  148.             local GameTime = math.floor(workspace.DistributedGameTime+0.5)
  149.             local Hour = math.floor(GameTime/(60^2))%24
  150.             local Minute = math.floor(GameTime/(60^1))%60
  151.             local Second = math.floor(GameTime/(60^0))%60
  152.            
  153.             if OldHour ~= Hour then
  154.                 spawn(function()
  155.                     pcall(function()
  156.                         local Old = Hours:FindFirstChild("Old")
  157.                         TweenService:Create(Old, TweenInfo.new(0.5), {Position = UDim2.fromScale(0,-1)}):Play()
  158.                         wait(0.5)
  159.                         Old:Destroy()
  160.                     end)
  161.                 end)
  162.                 NewHour = Instance.new("TextLabel")
  163.                 NewHour.Name = "Old"
  164.                 NewHour.Text = Hour
  165.                 NewHour.Size = UDim2.fromScale(1,1)
  166.                 NewHour.Font = Enum.Font.Gotham
  167.                 NewHour.Position = UDim2.fromScale(0,1)
  168.                 NewHour.TextColor3 = Color3.fromRGB(255,255,255)
  169.                 NewHour.TextSize = 12
  170.                 NewHour.BackgroundTransparency = 1
  171.                 NewHour.Parent = Hours
  172.                 pcall(function()
  173.                     TweenService:Create(NewHour, TweenInfo.new(0.5), {Position = UDim2.fromScale(0,0)}):Play()
  174.                 end)
  175.             end
  176.            
  177.             if OldMinute ~= Minute then
  178.                 spawn(function()
  179.                     pcall(function()
  180.                         local Old = Minutes:FindFirstChild("Old")
  181.                         TweenService:Create(Old, TweenInfo.new(0.5), {Position = UDim2.fromScale(0,-1)}):Play()
  182.                         wait(0.5)
  183.                         Old:Destroy()
  184.                     end)
  185.                 end)
  186.                 NewMinute = Instance.new("TextLabel")
  187.                 NewMinute.Name = "Old"
  188.                 NewMinute.Text = Minute
  189.                 NewMinute.Size = UDim2.fromScale(1,1)
  190.                 NewMinute.Font = Enum.Font.Gotham
  191.                 NewMinute.Position = UDim2.fromScale(0,1)
  192.                 NewMinute.TextColor3 = Color3.fromRGB(255,255,255)
  193.                 NewMinute.TextSize = 12
  194.                 NewMinute.BackgroundTransparency = 1
  195.                 NewMinute.Parent = Minutes
  196.                 pcall(function()
  197.                     TweenService:Create(NewMinute, TweenInfo.new(0.5), {Position = UDim2.fromScale(0,0)}):Play()
  198.                 end)
  199.             end
  200.            
  201.             if OldSecond ~= Second then
  202.                 spawn(function()
  203.                     pcall(function()
  204.                         local Old = Seconds:FindFirstChild("Old")
  205.                         TweenService:Create(Old, TweenInfo.new(0.5), {Position = UDim2.fromScale(0,-1)}):Play()
  206.                         wait(0.5)
  207.                         Old:Destroy()
  208.                     end)
  209.                 end)
  210.                 NewSecond = Instance.new("TextLabel")
  211.                 NewSecond.Name = "Old"
  212.                 NewSecond.Text = Second
  213.                 NewSecond.Size = UDim2.fromScale(1,1)
  214.                 NewSecond.Font = Enum.Font.Gotham
  215.                 NewSecond.Position = UDim2.fromScale(0,1)
  216.                 NewSecond.TextColor3 = Color3.fromRGB(255,255,255)
  217.                 NewSecond.TextSize = 12
  218.                 NewSecond.BackgroundTransparency = 1
  219.                 NewSecond.Parent = Seconds
  220.                 pcall(function()
  221.                     local SecondTween = TweenService:Create(NewSecond, TweenInfo.new(0.5), {Position = UDim2.fromScale(0,0)});
  222.                     SecondTween.Completed:Connect(ClearAll);
  223.                     SecondTween:Play();
  224.                 end)
  225.             end
  226.            
  227.             OldHour, OldMinute, OldSecond = Hour, Minute, Second
  228.  
  229.         end
  230.        
  231.         spawn(function()
  232.             while wait() do
  233.                 UpdateTime()
  234.             end
  235.         end)
  236.     end
  237.  
  238.     if Settings.FPS then
  239.         local FPS = Instance.new("Frame")
  240.         FPS.Name = Settings.Center and "2" or "1"
  241.         FPS.BorderSizePixel = 0
  242.         FPS.BackgroundColor3 = Color3.fromRGB(30,30,30)
  243.         FPS.Size = UDim2.fromScale(0,1) + UDim2.fromOffset(60)
  244.         FPS.Parent = Container
  245.        
  246.         local FPSContainer = Instance.new("Frame")
  247.         FPSContainer.Name = "Container"
  248.         FPSContainer.BackgroundColor3 = Color3.fromRGB(40,40,40)
  249.         FPSContainer.BorderSizePixel = 0
  250.         FPSContainer.Size = UDim2.fromScale(1,1) - UDim2.fromOffset(2,2)
  251.         FPSContainer.Position = UDim2.fromOffset(1,1)
  252.         FPSContainer.Parent = FPS
  253.        
  254.         local FPSValue = Instance.new("TextLabel")
  255.         FPSValue.Name = "Value"
  256.         FPSValue.BackgroundTransparency = 1
  257.         FPSValue.Font = Enum.Font.Gotham
  258.         FPSValue.TextSize = 12
  259.         FPSValue.Text = "NaN FPS"
  260.         FPSValue.TextColor3 = Color3.fromRGB(255,255,255)
  261.         FPSValue.Size = UDim2.fromScale(1,1)
  262.         FPSValue.Parent = FPSContainer
  263.        
  264.         local function RoundTo(N, DP)
  265.             return math.floor(N*(10^DP))/(10^DP)
  266.         end
  267.  
  268.         local CacheSize = Settings.CacheSize or 5
  269.  
  270.         local FPSCache = table.create(CacheSize, 0)
  271.  
  272.         local function ShiftFPSCache(ShiftFPS)
  273.             for i = CacheSize, 1, -1 do
  274.                 FPSCache[i] = FPSCache[i - 1] or ShiftFPS
  275.             end
  276.         end
  277.  
  278.         local function GetFPSAverage()
  279.             local Sum = 0
  280.  
  281.             table.foreach(FPSCache, function(_, CachedFPS)
  282.                 Sum += CachedFPS
  283.             end)
  284.  
  285.             return Sum / CacheSize
  286.         end
  287.        
  288.         local function UpdateFPS(ClientFPS)
  289.             ShiftFPSCache(ClientFPS)
  290.             local AverageFPS = GetFPSAverage()
  291.             local TextSize = TextService:GetTextSize((RoundTo(AverageFPS, Settings.Decimals) .. " FPS"), FPSValue.TextSize, FPSValue.Font, Vector2.new(0,0)).X
  292.             FPS.Size = UDim2.fromScale(0,1) + UDim2.fromOffset(TextSize+10,0)
  293.             FPSValue.Text = (RoundTo(AverageFPS, Settings.Decimals) .. " FPS")
  294.             AlignContainer()
  295.         end
  296.        
  297.         spawn(function()
  298.             game:GetService("RunService").RenderStepped:Connect(function(Delta)
  299.                 UpdateFPS(1 / Delta);
  300.             end)
  301.         end)
  302.     end
  303.     AlignContainer()
  304. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement