os.time() returns how many seconds have passed since the Unix epoch (1 January 1970, 00:00:00)
knowing this, you’ll have to convert it into hours, minutes, and seconds for your timer: (assuming your numTime variable is in unix epoch time)
-- Rearrange this because in most cases, the os time will be greater than your variable
local nextRefresh = os.time() - numTime.Value
-- Convert to hours
nextRefresh / 3600
-- Convert to minutes
nextRefresh / 60
-- Convert to seconds
nextRefresh
If you need anything else, don’t be afraid to ask! :]
i am trying to create a timer that will count 24 hours to the next day and the first os.time() start from the value then player joined and got daily quests
game.Players.PlayerAdded:Connect(function(player)
local foundData = DailyRewardDataStore:GetAsync(player.UserId)
local numTime = Instance.new("NumberValue",player)
numTime.Name = "numTime"
if foundData then
if tonumber(foundData) < os.time() - 86400 then
local cur = os.time()
DailyRewardDataStore:SetAsync(player.UserId,cur)
module.CreateQuests(player)
numTime.Value = cur
end
else
local cur = os.time()
module.CreateQuests(player)
DailyRewardDataStore:SetAsync(player.UserId,cur)
numTime.Value = cur
end
end)
According to the docs, GetServerTimeNow returns the epoch time on the server with microsecond precision. and with your problem of the -478098 your saved variable may not be using this new Workspace:GetServerTimeNow variable.
Finally, just fixed that. The problem was that is was setting value of numTime only the time you join and you have no data or you was online last time more than 24 hours, i fixed by adding else