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
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
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
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
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)