Making a script that detects if it is a certain time universally

I am having terrible issues on how to make this and I do not know how to word this properly.

I am trying to make a script that detects if it is a specific time like 6 am utc+8 or something like that, and it would trigger a few functions, mainly my system to reset a player’s daily missions. I would also need it to be able to detect if it has passed the specific time for players who joined later so it would also reset their missions.

I am sorry if I confuse you, I cannot think straight right now and I do not know how to explain it very well.

1 Like

After doing some research, I wasn’t able to find an explicit answer. It seems like you can either use os.time or DateTime to get similar results. It seems that DateTime is the preferred method as it has more functionality.

Only call this on the server for use-cases like this. This function will use the device’s local time, which can be modified by the user.

It’s okay to run this on the client, but the actual verification should be done server-side.


Both methods are pretty similar:

local daysInSeconds = 60^2*24

os.time

local lastClaim = os.time()
local nextClaim = os.time() + daysInSeconds
local secondsUntilClaim = nextClaim - lastClaim

if secondsUntilClaim <= 0 then
	print('Ready to claim!')
else
	print(secondsUntilClaim .. ' until next claim!')
end

DateTime

local lastClaim = DateTime.now().UnixTimestamp
local nextClaim = lastClaim + daysInSeconds
local secondsUntilClaim = nextClaim - lastClaim

if secondsUntilClaim <= 0 then
	print('Ready to claim!')
else
	print(secondsUntilClaim .. ' until next claim!')
end

Note that this shouldn’t be used specifically for client-server syncing, as GetServerTimeNow should be used for that.

3 Likes

tick() or workspace:GetServerTimeNow()

1 Like

@MightyDantheman Is right, DateTime is the preferred method, Especially UniversalTime

You should look more into the document and google if there are any better ways.

1 Like