Os.date() problem? [SOLVED]

  1. What do you want to achieve? Keep it simple and clear!
    I wan’t to make a live event script

  2. 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.

  3. 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

2 Likes

Please do provide use your code so we can better understand your situation, 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.

You should refer to the Lua OS docs, and go from UTC time using “!*t” to get UTC time, adapt as required.

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.

visit a similar post

it explains how you can sync the time ,

Crazy Man 32 also created a module for this purpose ,here’s the link to the model
https://www.roblox.com/library/182602810/GetDate

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

!*t is what I recommended, if you visit the post, on the client that is,

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

sorry by not being active on this topic

where did you place this and is it a local script

at serverscriptservice and is a script

That’s fine. Put the code in a code block to be better.
Use 3 tildas (`) at the start and end of the post.

1 Like
-- 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

Here is OP’s code formatted and indented.

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
1 Like

i did and now it prints:

bad argument #1 to ‘date’ (string expected, got no value)

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)


Source: os

I’m not sure how it will work in a server script so I advise you to check it.

1 Like

@Conejin_Alt

local date = os.date("*t")

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.