How do I increase clock time

The server script calls the function in module script that increases the time by 1 second which works perfectly fine.

However I’m having it hard to come up with a method to be able and increase the clock time by desired amount example: 3:00:05, increasing it by 3 hours and 5 seconds while it still does the normal operation a clock would.

So if the clock was to be 06:00:00 and I wanted to increase the clock time by 3:00:05 with a click of a button which would make it 09:00:05 and the clock would still go perform the normal operation: 09:00:06, 09:00:07, 09:00:08 - etc.

Server script:

--- Service
local ServerScriptService = game:GetService("ServerScriptService")

--- Module
local Manager = require(ServerScriptService.DataStore.Manager)

task.wait(4)

while true do
	Manager.Time()
	task.wait(1)
end

Module script:

function module.Time(Hour: number, Minutes: number, Seconds: number)
	local Profile = module.Profiles[PlayerSaved]
	if not Profile then return end
	
	local function time()
		local t = tick()
		local hour = math.floor(t/3600) % 24
		local min = math.floor(t/60) % 60
		local sec = math.floor(t%60)

		if min <= 9 and sec <= 60 then
			min = "0"..min
			sec = "0"..sec
		end
		
		workspace.TimeDisplay.Clock.Screen.SurfaceGui.Display.Text =  hour..":"..min..":"..sec
	end
	
	time()
end

Clock: I made it only display hours and minutes don’t mind it not displaying seconds
image

2 Likes

like timezones or just to add an offset in the time?

1 Like

Yeah just an offset in the time

1 Like

also what are the parameters in module.Time() for? you don’t even use it in the server script

1 Like

you can just add or subtract in tick()

2 Likes

it adds the function into the module

1 Like

no i meant the (Hour: number, Minutes: number, Seconds: number)

1 Like

I was using them when trying to find a method

1 Like

So like you could input the amount of hours, min and second you want to increase.

2 Likes

why do you use tick() and if you replace it with something else it will be bad for you?

2 Likes

I use tick to make the time look as if it was the player local time, so If a player joines the game at 14:50 it will display 14:50 on the clock, It wouldnt be bad but it would be that nice feature for the player to see the clock is same as their local time

1 Like

Thats not how it works. You are reading tick() from server, which means its getting the time when server started in its own local time, which could be in a different country than the player is located, thats not a local time of your player. If you want to get the real time of the player you should check the time from a local script

2 Likes

oh! you convert the hours, minutes, and seconds to seconds then add it to tick()

an hour has 3600 seconds and a minute has 60 seconds

so you should have these variables

local offsetHours = Hour * 3600
local offsetMinutes = Minutes * 60
local offsetSeconds = Seconds

then add them all together and add to tick

function module.Time(Hour: number, Minutes: number, Seconds: number)
	local Profile = module.Profiles[PlayerSaved]
	if not Profile then return end
	
	local function time()
		local offsetHours = Hour * 3600
		local offsetMinutes = Minutes * 60
		local offsetSeconds = Seconds
		
		local t = tick() + (offsetHours + offsetMinutes + offsetSeconds)
		local hour = math.floor(t/3600) % 24
		local min = math.floor(t/60) % 60
		local sec = math.floor(t%60)

		if min <= 9 and sec <= 60 then
			min = "0"..min
			sec = "0"..sec
		end
		
		workspace.TimeDisplay.Clock.Screen.SurfaceGui.Display.Text =  hour..":"..min..":"..sec
	end
	
	time()
end

and lastly, on the server script you can put the offset you want

--- Service
local ServerScriptService = game:GetService("ServerScriptService")

--- Module
local Manager = require(ServerScriptService.DataStore.Manager)

task.wait(4)

while true do
	Manager.Time(3, 0, 5)
	task.wait(1)
end
2 Likes

Yes but its a solo player game.

1 Like

Server doesnt care if its a solo player or not, tick() gotten from server its not the local time of your player

1 Like

she’s still right, even if you do it in solo server tick will still use the GMT/UTC time zone instead of your local timezone

2 Likes

I know but if I was to do a local script too it would take more time than I expect, the tick() is doing its job, if the player joins at 15:50 it will display 15:50 on the clock even after, if the time was 15:55 the clock will have increased to 15:55

Its “doing its job” because you are testing it in studio, which means the server and the client its your own computer, thats why the time its the same, test it in a real server, and the server could be away from you which means the tick() will use the local time of that computer/server (well… which rarely will be far away from your location)

1 Like

Okay, I tested I see what you mean, I guess I won’t have that nice feature then.

I will try this in a moment, thanks