#how i can make a server age on a toolbar
6 messages · Page 1 of 1 (latest)
It's true that workspace.DistributedGameTime reports the server's uptime, but if you wish to respect fully client-sided UI development, that value will only tell you the amount of time elapsed since the client started playing the game. To fix this, have the client retrieve the server's uptime through a RemoteFunction, and send along a Unix timestamp to allow the client to compensate for latency (determine how much time it took for you to receive the request and update the server's uptime accordingly). Finally, start an upward timer from the server's uptime and format it to your GUI
I'm feeling generous today, @split gale
--[[
Author Zffixture (74087102)
Date 24/04/21 (YY/MM/DD)
Version 1.0.0b
]]
--!strict
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local GetServerUptime = ReplicatedStorage:WaitForChild("GetServerUptime")
local Container = script.Parent
local Timer = Container:WaitForChild("Timer")
local TIMER_FORMAT = "Server Age: %02d:%02d:%02d"
local MAX_FRAME_SIZE = Vector2.one * math.huge
local PADDING = Vector2.new(25, 5)
local function formatTimer(seconds: number)
local hours = seconds // 3600
local minutes = seconds % 3600 // 60
local seconds = seconds % 60
Timer.Text = string.format(TIMER_FORMAT, hours, minutes, seconds)
end
local function resizeTimer()
local newSize = TextService:GetTextSize(
Timer.Text,
Timer.TextSize,
Timer.Font,
MAX_FRAME_SIZE
)
Timer.Size = UDim2.fromOffset(
newSize.X + PADDING.X,
newSize.Y + PADDING.Y
)
end
local function startTimer()
local serverUptime, sentTimestamp = GetServerUptime:InvokeServer()
-- Offset server uptime by the amount of time it took to receive the value:
serverUptime += os.time() - sentTimestamp
-- While the ScreenGui is a descendant of the Data Model:
while Container.Parent do
formatTimer(serverUptime)
resizeTimer()
serverUptime += task.wait()
end
end
startTimer()