I want to fire an event at 2:00 pm every day but i don't have any clue on how to do that
COMMUNITY QUESTION
What is a good way to fire an event in the same time everyday??
2 answers
If you want to do this the most efficient way, you need to use os.date or @XAXA's Synced Time Module which gets the time from Google.
Remember to enable HTTP Requests in your game settings.
local monthStrMap = {
Jan=1,
Feb=2,
Mar=3,
Apr=4,
May=5,
Jun=6,
Jul=7,
Aug=8,
Sep=9,
Oct=10,
Nov=11,
Dec=12
}
local HttpService = game:GetService("HttpService")
local function RFC2616DateStringToUnixTimestamp(dateStr)
local day, monthStr, year, hour, min, sec = dateStr:match(".*, (.*) (.*) (.*) (.*):(.*):(.*) .*")
local month = monthStrMap[monthStr]
local date = {
day=day,
month=month,
year=year,
hour=hour,
min=min,
sec=sec
}
return os.time(date)
end
local isInited = false
local originTime = nil
local responseTime = nil
local responseDelay = nil
local function inited()
return isInited
end
local function init()
if not isInited then
local ok = pcall(function()
local requestTime = tick()
local response = HttpService:RequestAsync({Url="http://google.com"})
local dateStr = response.Headers.date
originTime = RFC2616DateStringToUnixTimestamp(dateStr)
responseTime = tick()
-- Estimate the response delay due to latency to be half the rtt time
responseDelay = (responseTime-requestTime)/2
end)
if not ok then
warn("Cannot get time from google.com. Make sure that http requests are enabled!")
originTime = os.time()
responseTime = tick()
responseDelay = 0
end
isInited = true
end
end
local function time()
if not isInited then
init()
end
return originTime + tick()-responseTime - responseDelay
end
return {
inited=inited,
init=init,
time=time
}
From there on, have a look at this tutorial: https://devforum.roblox.com/t/how-to-make-server-synced-daily-shops/632401
If I helped, please mark this as a solution and maybe even Subscribe to my YouTube channel where I create Scripting Tutorials that teach you how to code!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
hi man, thanks for the reply! I've tested the script but it didn't work for some reason