Inconsistency with comparing tick() to a number saved via Data Stores

I am working on a 2X Exp developer product and the way I handled it was to use tick()

I save the sum of tick() of the time of purchase + the number of seconds for the game product to last.

Example code:

local playerkey = “user” player.userId
local expTime = math.floor(tick()) + 3600 — 1 hour worth of time
DataStore:SetAsync(playerkey, expTime)

After that, I have the code that determines the number of time left for double points by:

local initialTime = DataStore:GetAsync(playerkey)
if initialTime and initialTime - math.floor(tick()) > 0 then
print("Time left : " …initialTime - math.floor(tick()))
end

And the problem is that when I switch servers, the print output gives me completely different numbers. I know tick() constantly changes, but the difference I got from switching servers was from 3,000~ seconds to 10,000~ seconds. However, when I rejoined the server where the data was originally saved in, the difference went back to 3,000~ seconds.

Is the DataStore not saving numbers properly?
Or is the tick() giving me different values when I join different servers?

tick() gives you the Unix timestamp, which varies by server - not a very good function to save time differences with.

If you want a constant source, you’re probably better off getting Unix time from an external server that keeps the same time via HttpService.

Use os.time().

1 Like

I have no idea how to use HTTP service as of now… is there another way around this?

Nice, but can’t they then switch their operating system time to sometime in the past to bypass the expiration?

[quote] Use os.time(). [/quote]The os library does not exist in ROBLOX Lua.

Hmm awesome, this seems to have solved the problem so far.

Nice, but can’t they then switch their operating system time to sometime in the past to bypass the expiration?[/quote]
os.time(), called server-side, returns the true UNIX time. I am unsure of client-side behaviour.

Where’s that in the Wiki? o.e

Wiki Writers :

Create a page for that !

Since when was the os library usable?

Edit, only time() and difftime() are accessible.

Since when was the os library usable?

Edit, only time() and difftime() are accessible.[/quote]Yeah, I was surprised as well. Great to know they made those two functions usable.

Since when was the os library usable?

Edit, only time() and difftime() are accessible.[/quote]Yeah, I was surprised as well. Great to know they made those two functions usable.[/quote]

It would be really great if they also made date() accessible. Then we would be able to have special events during different days of the week. And possibly something like double points on weekends.