How to get server uptime

I’ve tried so many different things to no avail. Tried with time() too, still doesn’t work. Ideally, I just wanna get the start time once (when you join the game) and it’ll automatically update the necessary info for the client, without making calls to the server every second

local StartTime = SettingsService:GetServerStart()
print(StartTime)
task.spawn(function()
	while true do
		self.HUD.Settings.Uptime.Text = "Server started: " .. os.date("%c", StartTime) .. "  |  Server uptime: " .. Library:ConvertTime(os.time() - StartTime, 3)
		
		task.wait(1)
	end
end)

ConvertTime just turns the seconds in H:M:S

1 Like

In a server script you can set an attribute on ReplicatedStorage with the server start time os.time(), then access that once in a client script. After that you can update every second with the difference between the os.time() and the start time. Here is a place I just made where it is done:
https://www.roblox.com/games/9976295163/test

You should use workspace.DistributedGameTime, its the time since the server started, and it can be accessed by the client so no server calls needed.

2 Likes

workspace.DistributedGameTime exists.

local ServerStart = os.time()
local currTime = "Server started: "..os.date("%c",ServerStart).." | Server uptime: "..math.floor(workspace.DistributedGameTime)
2 Likes