A timer that saves forever

You can write your topic however you want, but you need to answer these questions:

  1. I want a timer that counts up from 0 to inf even after someone leaves for example 1 hour and then join back i want the timer to be an hour higher

  2. i cannot find someone talking about this anywhere

My script currently is =

local startTime = os.time()

local TextLabel = script.Parent


local function sToHMS(s)
	local h = math.floor(s/3600)
	s = s % 3600
	local m = math.floor(s/60)
	s = s % 60
	return string.format("%02i:%02i:%02i", h, m, s)
end

game:GetService("RunService").RenderStepped:Connect(function()
	TextLabel.Text = sToHMS(os.time() - startTime)
end)

That should work! Do you need help saving the startTime in a datastore?

Sure but if you join back does it start later cause i want it to go on forever even if nobody is in the server

Servers automatically close when there is no one in it

Yeah! the script you shared does not need to be “running” the time elapsed is calculated on-use, as long as you save to a datastore the timestamp method will work nicely. You will need to keep track of saveTime on the server (Script instead of LocalScript) to save it.

I wouldn’t use a data store, if they are trying to count up from a specific point in time (e.g how long has it been since last Christmas, for example), then I would just find the os.tick value for that date and use that as a constant

e.g.

local startTime = 4928482 

local TextLabel = script.Parent


local function sToHMS(s)
	local h = math.floor(s/3600)
	s = s % 3600
	local m = math.floor(s/60)
	s = s % 60
	return string.format("%02i:%02i:%02i", h, m, s)
end

game:GetService("RunService").RenderStepped:Connect(function()
	TextLabel.Text = sToHMS(os.time() - startTime)
end)

The start time I put was a random number, but you can put it as whatever you want