generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Date Counter

Previous Thread :: Next Thread 
RIPPER0NI is not online. RIPPER0NI
Joined: 14 Apr 2011
Total Posts: 141
28 Nov 2017 08:01 AM
Hello.
I am making a game, and I want to have a counter which is going to say the days left until christmas.

The problem is that every new server the date will be what I set in studio.

Is there a way to make it so that I can have globally across all servers that will update across all servers at the same time and all the identical


Report Abuse
WillieTehWierdo200 is not online. WillieTehWierdo200
Joined: 13 Aug 2008
Total Posts: 1147
28 Nov 2017 09:42 AM
function getTimeUntil(t)
local reservoir = os.difftime(t, os.time())
local secs = reservoir % 60
reservoir = math.floor(reservoir/60)
local mins = reservoir % 60
reservoir = math.floor(reservoir/60)
local hours = reservoir % 24
reservoir = math.floor(reservoir/24)
local days = reservoir % 365
return days, hours, mins, secs
end

local christmas = os.time({year=2017, month=12, day=25, hour=1, min=0, sec=0})
print(string.format(
"%d days, %d hours, %d minutes and %s seconds until Christmas!",
getTimeUntil(christmas)
))
--> 26 days, 9 hours, 20 minutes and 25 seconds until Christmas!


Report Abuse
WillieTehWierdo200 is not online. WillieTehWierdo200
Joined: 13 Aug 2008
Total Posts: 1147
28 Nov 2017 02:13 PM
This version will repeat the countdown line every second, updating the output. You can use the loop in the same way to update a TextLabel or whatever you want instead of just printing to the output window.

function unpackTimeSpan(fromTime, toTime)
local reservoir = os.difftime(toTime, fromTime)
local secs = reservoir % 60
reservoir = math.floor(reservoir/60)
local mins = reservoir % 60
reservoir = math.floor(reservoir/60)
local hours = reservoir % 24
reservoir = math.floor(reservoir/24)
local days = reservoir % 365
return days, hours, mins, secs
end

local now = os.time()
local christmas = os.time({year=os.date("*t", now).year, month=12, day=25, hour=1, min=0, sec=0})
while wait(1) do
now = now + 1
print(
string.format(
"%d days, %d hours, %d minutes and %s seconds until Christmas!",
unpackTimeSpan(now, christmas)
)
)
end


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image