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

os.time going into negitive time?

Asked by 8 years ago

Idea Make a simple reward system that will reward the player after 24:00:00 Using the os.time() function.
Issue The timer goes into a negative time, as a result It shows up as things like (-21:02:13)
Code1



~~local RewardTime = 24*60*60 --How often they get the reward in seconds --This is 24 hours local DataStore = game:GetService("DataStoreService"):GetDataStore("LastLogin") local Player = script.Parent.Parent.Parent.Parent.Parent local LastLogin = DataStore:GetAsync(Player.userId) or os.time() while true do Seconds = RewardTime-(os.time()-LastLogin); Minutes = Seconds/60; Hours = Minutes/60; script.Parent.Text = ("Time Until Next Reward: d:d:d"):format(Hours,Minutes%(60),Seconds%(60)) wait(1) end

Code2

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)

Thanks :D

Answer this question