Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How can I create a "live" function?

Asked by 4 years ago

I want to create a certain function that would activate on a certain MM/DD/YY. How could I do this? I'm not being super specific, but It's kinda tough to explain.

0
Use os.time Unscriptablee 20 — 4y
0
Ill try that! happyhal75 32 — 4y

1 answer

Log in to vote
3
Answered by 4 years ago
Edited 4 years ago

You can use os.date() for this. os.date() takes two variables, what time zone and what time (os.time()). For time zone you should pretty much always use "!(asterisk)t" which means UTC time, which is the standard, but if you want local timezone, use "(asterisk)t" instead. For time you should just leave it blank, because it takes os.time() automatically, unless you need to figure out what the date would be of a certain time.

Once you put it into a variable, it has the year, month, day, hour, minute, second, and several other things that might sometimes be useful. You can use this to compile any time into a date. An example would be using it to create the date of the time when the script was run.

time = os.date("!*t") 

print(time.month.."/"..time.day.."/"..time.year) -- mm/dd/yyyy

If you were to run the script right now, the script would print "11/10/2019" into the output. If you were to run it sometime after, it would print the date of the day it was run.

For the question, you could make it so it detects what day it is, and if it is the day that function is supposed to run, it will call the function.

0
also, replace (asterisk) with * Inconcinnus 90 — 4y
0
oh gloveshun 119 — 4y
0
can you tell me how? gloveshun 119 — 4y
0
I tried doing that you said with Run Service and it only worked if I hit play during that certain time the function was told to run. happyhal75 32 — 4y
View all comments (2 more)
0
you probably could make a while loop that does "while os.time() % 86400 == 0 do -- check date end Inconcinnus 90 — 4y
0
ofc you would also check the date when the player first joins Inconcinnus 90 — 4y
Ad

Answer this question