Server age counter starts from 1 hour?

I think this is quite self explanatory;

local rStorage = game:GetService("ReplicatedStorage")
local startTime = rStorage:WaitForChild("ServerStartTime")

local cafe = workspace:WaitForChild("Cafe")
local tv = cafe:WaitForChild("TV")

local serverInfoPart = tv:WaitForChild("ServerInfoPart")
local surfaceGui = serverInfoPart:WaitForChild("SurfaceGui")
local serverAgeText = surfaceGui:WaitForChild("ServerAgeText")

function FormatTime(seconds)
	local hours = math.floor(seconds / 3600)
	local minutes = math.floor((seconds % 3600) / 60)
	local secs = math.floor(seconds % 60)
	return string.format("%d hours, %d minutes, and %d seconds", hours, minutes, secs)
end

function UpdateLabel()
	while true do
		local currentTime = tick()
		local elapsedTime = currentTime - startTime.Value
		serverAgeText.Text = FormatTime(elapsedTime)
		task.wait(1)
	end
end

UpdateLabel()

For testing purposes i made my own version and it works as intended?

local startTime = tick()

function FormatTime(seconds)
	local hours = math.floor(seconds / 3600)
	local minutes = math.floor((seconds % 3600) / 60)
	local secs = math.floor(seconds % 60)
	return string.format("%d hours, %d minutes, and %d seconds", hours, minutes, secs)
end

function UpdateLabel()
	while true do
		local elapsedTime = tick() - startTime
		print(FormatTime(elapsedTime))
		task.wait(1)
	end
end

UpdateLabel()

Use time() instead, which returns the amount of time, in seconds, that has elapsed since the current game instance started running.

Make sure the value inside of startTime.Value is initialized on server Startup

so basically

local rStorage = game:GetService("ReplicatedStorage")
local startTime = rStorage:WaitForChild("ServerStartTime")

local cafe = workspace:WaitForChild("Cafe")
local tv = cafe:WaitForChild("TV")

local serverInfoPart = tv:WaitForChild("ServerInfoPart")
local surfaceGui = serverInfoPart:WaitForChild("SurfaceGui")
local serverAgeText = surfaceGui:WaitForChild("ServerAgeText")

function FormatTime(seconds)
	local hours = math.floor(seconds / 3600)
	local minutes = math.floor((seconds % 3600) / 60)
	local secs = math.floor(seconds % 60)
	return string.format("%d hours, %d minutes, and %d seconds", hours, minutes, secs)
end

function UpdateLabel()
	while true do
		local currentTime = tick()
		local elapsedTime = currentTime - startTime.Value
		serverAgeText.Text = FormatTime(elapsedTime)
		task.wait(1)
	end
end
startTime.Value = tick() -- Initialize The startTime.Value to the current Tick [On Startup]
UpdateLabel()

this seems to fix it, thanks charrrrr

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.