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

how can i record the time using roblox server?

Asked by 9 years ago

i have a script that gives player a perk for 24hours. sometimes it doesn't work because the request is taking too long and returning nil i think. i made some prints at key points throughout my script and sometimes it returns to me the print for "timed out" which means it's not getting the time. i have tested this and it works if it returns the time, but it's not always returning the time. i'm using

game:GetService("HttpService"):GetAsync("http://www.timeapi.org/utc/now?%25Q", true)

to record the time and then using it again later to check the time. i'm not sending a bunch of requests. it only makes the request once during purchase, and once when player either enters the game or resets their character. like i said it all works fine except i think like today there was alot of traffic on the internet and it was just not receiving the request.

so, is there a way for my to get the time on/from the game server?

1
Why not os.time() function. You can get the current time stamp and add (60*60*24) --60 seconds, 60 minutes, 24 hours. Since is.time goes by seconds. You do not need a external http location for time stamp unless you want the actual date. M39a9am3R 3210 — 9y

1 answer

Log in to vote
1
Answered by
noliCAIKS 210 Moderation Voter
9 years ago

The problem is that the site is too slow. You could check if downloading the time worked and repeat until it worked correctly, but it would be a lot more efficient to use os.time() like M39a9am3R mentioned, which does the same. On the wiki it also mentions the option to call it with a table, but in this case you can simply do this:

local expirationTime = os.time() + 24 * 3600

Then you can store this somewhere if you want. Since expirationTime is a number instead of a string like you would've gotten if you used HttpService, to check if the perk has expired, use this:

if os.time() >= expirationTime then
    -- The item has expired.
end

Because os.time() always returns the time in UTC, it will be independent of the server you use it on and it will give you the same result as you would've gotten if you had used timeapi.org instead.

0
thx so much guys. this works. i've been using it for a few days now and no problems :D johnnygadget 50 — 9y
Ad

Answer this question