Answered by
6 years ago Edited 6 years ago
Firstly, I'd like to point out that you are using or
incorrectly. When you do x == y or z
, y
is compared to x
, but z
is not compared to x
, it is instead treated as its own condition.
The reason for your if
's condition always being met is because in Lua, any value that is not false
or nil
is treated as truthy
in a boolean context, so these examples would print:
Since the conditions used are not false or nil (falsey), the condition is met.
What you are looking for is x == y or x == z
.
However you are checking tons of numbers, and doing if a == b or a == c or a == d or .... then.
would get tedious very quickly. I noticed that the numbers are all divisible by 60, so you can use the modulo operator %
. It basically divides two numbers and returns the remainder after division.
03 | currentTime.Value = "Time - " ..minutes.. ":0" ..seconds |
14 | currentTime.Value = "Time - " ..minutes.. ":" ..seconds |
From what I understood from your script you attempted to format a number as timer (e.g. 3:00
). If so, you can use this handy function:
1 | local function timer_format(x) |
2 | return math.floor(x/ 60 ) .. ":" .. (x % 60 < 10 and "0" or "" ) .. x % 60 |
7 | print (timer_format( 120 )) |
Hopefully this answered your question and if it did, then don't forget to hit that "Accept Answer" button. If you have any other questions then feel free to leave them down in the comments below.
Have a wonderful day