What do you want to achieve? Keep it simple and clear!
I wan’t to make a live event script
What is the issue? Include screenshots / videos if possible!
The script doesn’t works when i test it (Maybe only in studio?) for example:
-If my time is 9:59AM and the event is at 10AM, when is 10AM nothing happens. I just wrote an else code if it’s not 10AM and when is 10AM still prints as is not. When is it.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I saw the developer hub or posts about os.date() or MessageService but i don’t know how to use it or sometimes the information about it is poorly made
I just started with the os.date() stuff, i noticed MessageService and i don’t know how to use it, if you know how do i use MessageService then tell me how. Thanks
It would help if you uploaded your code to the forum so that others can try to identify possible errors and help you through them. I also suggest you use os.time() when creating a live event script.
On the client, you should call os.date("*t", some_time_value) to get a table containing the year/month/day/etc for the value that os.time() returned. The reason you should do this on the client is because the *t option uses the client’s local timezone, as opposed to the !*t option which will show the UTC date for the given timestamp.
OP wants their specific time for them, not the time of the user. For more accurate and correct timing, !*t should be used and adapted to meet which timezone that is required.
Edit: Moved to DM to prevent filling the post up w/ this convo
local date = os.date(“*t”, os.time())
while wait() do
if date[“month”] == 11 and date[“day”] == 29 and date[“hour”] == 19 and date[“min”] >= 49 then
print(“Event”)
else
print(“Noevent”)
end
end
-- Script in ServerScriptService --
local date = os.date("*t", os.time())
while wait() do
if date[“month”] == 11 and date[“day”] == 29 and date[“hour”] == 19 and date[“min”] >= 49 then
print(“Event”)
else
print(“Noevent”)
end
end
while wait() do
if date[“month”] == 11 and date[“day”] == 29 and date[“hour”] == 19 and date[“min”] >= 49 then
print(“Event”)
else
print(“Noevent”)
end
end
You have to update the date in every iteration, otherwise this makes no sense.
while wait(1) do
local date = os.date("*t", os.time())
if date["month"] == 11 and date["day"] == 29 and date["hour"] == 19 and date["min"] >= 49 then
print("Event")
else
print("Noevent")
end
end
Did you copy the exact code that I posted?
Try this:
while wait(1) do
local date = os.date("*t")
if date["month"] == 11 and date["day"] == 29 and date["hour"] == 19 and date["min"] >= 49 then
print("Event")
else
print("Noevent")
end
end
It worked! And my last question: In studio the time used for os.date() is from your computer, and when it is playing on roblox servers will use UTC time? (Costa rica time + 6 Hours)
Will give the local time. This is based on where the server exists, so it can vary significantly.
local date = os.date("!*t")
Will ALWAYS give UTC time. This is very useful for events, as it will be synced across all servers (with maybe slight delays, nothing more than a second).
CC @Kacper
While wait() do loops are generally a bad practice.
For more information, see this article:
Ported over the the developer forum by @colbert2677 made by @cntkillme.