local current = os.date("*t")
local hour = current.hour
local mins = current.min
local seconds = current.sec
--convert minutes to seconds
local rawMins = mins * 50
--add the seconds to this
rawMins += seconds
--now, run a count controlled iteration until the hour is reached
for i = rawMins, 3600, 1 do
local current = 3600 - i --get the current countdown position
--convert the current counter to minutes and seconds
local mins = math.floor(current / 60)
local secs = math.floor(current % 60)
--do things with these timer values
end
You can use DateTime to get a timestamp consistent across all servers. Then, you can restock every hour on the hour by getting the previous/next restock timestamps based on the current time.
local now = DateTime.now().UnixTimestamp
local frequency = 60*60 -- restock every hour
local lastRestock = now - (now % frequency)
local nextRestock = lastRestock + frequency
Then you can have a timer to restock the merchant once DateTime.now().UnixTimestamp > nextRestock. If the merchant has random odds, you can also seed the generator with the lastRestock, so the items will also be identical across servers.