p0s_0
(pos0)
October 2, 2019, 7:08pm
#1
Hello,
I am trying to make a countdown to January 1st, 2020 countdown in Roblox, but it seems that I’m having the problem of having the daysLeft at 0. After reading this and this topic, I had a little bit of better understanding on how to do this, so I tried and, just like every game I make on Roblox, failed. The value of daysTill is 0, yet it should be 91 days. Here is my code and most of it is from this topic.
local newYearsDay = os.time({year=2020; month=1; day=1})
local secondsDiff = os.difftime(newYearsDay,os.time())
local secondsTill = secondsDiff%60
local minutesTill = math.floor(secondsDiff%3600/60)
local hoursTill = math.floor(secondsDiff%86400/3600)
local daysTill = math.floor(secondsDiff%(86400*30)/86400)
repeat
wait()
script.Parent.Time.Text = daysTill.." days until New Years."
until daysTill == 0
Thanks for reading!
I’d recommend using https://developer.roblox.com/en-us/api-reference/lua-docs/os#date to display this correctly
The first part of your code looks fine.
3 Likes
p0s_0
(pos0)
October 2, 2019, 7:12pm
#3
Hello,
When I click the link it goes to the website os.date instead of the dev hub. Might wanna fix that. Anyway, I’m trying this out.
Thanks!
p0s_0
(pos0)
October 2, 2019, 7:19pm
#4
Hello,
And, seems like I’m getting an error with my code.
Error:
Workspace.Part.SurfaceGui.Script:33: attempt to call local 'daysTill' (a number value)
Code:
repeat
wait()
script.Parent.Time.Text = os.date("*t" ,os.time(daysTill()))
until daysTill == 0
Thanks!
daysTill is a number, not a function. You’re calling it
1 Like
p0s_0
(pos0)
October 2, 2019, 7:20pm
#6
Thanks for letting me know about this, lol.
p0s_0
(pos0)
October 2, 2019, 7:22pm
#7
Now, I’m getting a different number, yay. Fun.
Error:
Workspace.Part.SurfaceGui.Script:34: bad argument #3 to 'Text' (string expected, got table)
Code:
local newYearsDay = os.time({year=2020; month=1; day=1})
local secondsDiff = os.difftime(newYearsDay,os.time())
local secondsTill = secondsDiff%60
local minutesTill = math.floor(secondsDiff%3600/60)
local hoursTill = math.floor(secondsDiff%86400/3600)
local daysTill = math.floor(secondsDiff%(86400*30)/86400)
repeat
wait()
local daysTill2 = tostring(daysTill)
script.Parent.Time.Text = os.date("*t" , daysTill2)
until daysTill == 0
Thanks!
grilme99
(brooke)
October 2, 2019, 7:28pm
#8
According to the wiki , os.date
reutens a table
.
You should correct it with this:
script.Parent.Time.Text = tostring(os.date("*t" , daysTill2).day)
1 Like
p0s_0
(pos0)
October 2, 2019, 7:30pm
#9
This seems to have solved the error, but it seems that to the game, there is only 31 days until new years! YAY! But really, there are only 91. Aww.
Here is my code:
local newYearsDay = os.time({year=2020; month=1; day=1})
local secondsDiff = os.difftime(newYearsDay,os.time())
local secondsTill = secondsDiff%60
local minutesTill = math.floor(secondsDiff%3600/60)
local hoursTill = math.floor(secondsDiff%86400/3600)
local daysTill = math.floor(secondsDiff%(86400*30)/86400)
repeat
wait()
local daysTill2 = tostring(daysTill)
script.Parent.Time.Text = tostring(os.date("*t" , daysTill2).day)
until daysTill == 0
grilme99
(brooke)
October 2, 2019, 7:31pm
#10
Please read the wiki page.
Field
Type
Description
day
int
An integer between 1 and 31 describing the current day of the month.
You’re going to have to do some math to calculate it.
1 Like
grilme99
(brooke)
October 2, 2019, 7:35pm
#11
I’d also like to add on:
What is the purpose of setting the text until daysTill == 0
? daysTill
isn’t updating so you’re just wasting performance by doing this.
Also, try and do this to fix it:
script.Parent.Time.Text = tostring(os.date("*t" , daysTill2).yday)
1 Like