Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does the os time only use local time?

Asked by 7 years ago
local DataStore = game:GetService("DataStoreService"):GetDataStore("LastLogin")


game.Players.PlayerAdded:connect(function(Player)
    wait()
    local LastLogin = DataStore:GetAsync(Player.userId)
    if LastLogin then
        local Seconds = os.time()-LastLogin
        local Minutes = Seconds/60
        local Hours = Minutes/60
        print("It has been: "..Hours.." hours Since your last reward")
        if Hours >= 24 then
            print("You get a daily login award")
            DataStore:SetAsync(Player.userId,os.time())
        end
    else
        DataStore:SetAsync(Player.userId,os.time())
    end
end)

I put this code on a server script in the workspace, but this only works with local time. I know this because i changed my date 1 day forward and it printed that i got an award and last reward was 24h ago.

I want to use server time for this, i think it's based off PST but whatever, as long as its not possible to loophole.

2 answers

Log in to vote
0
Answered by 7 years ago

It's adjusted for GMT, but it assumes that the system clock is actually the right time for its timezone. If the clock has the wrong time for the timezone, as my computer sometimes does, it will display the wrong time - It adjusts for the wrong time in the right timezone.

Just make sure that you do it on the server, and so long as the server has the correct time then it will always be right.

Ad
Log in to vote
0
Answered by 7 years ago

Is this run on studio? I believe it simply adjusts for timezone, so if you change what day it is then that will change - I believe that the servers are guaranteed to have the correct time, though (although different timezones)

Answer this question