✓ Accepted answer
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:
if 4 then
print(4)
end
if "text" then
print("text")
end
if {} then
print({})
end
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.
local seconds = 0
local minutes = 10
currentTime.Value = "Time - "..minutes..":0"..seconds
for i = 600, -1 do
wait(1)
if i % 60 == 0 then
minutes = minutes - 1
seconds = 59
elseif i == 0 then
seconds = 0
else
seconds = seconds - 1
end
currentTime.Value = "Time - "..minutes..":"..seconds
end
end
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:
local function timer_format(x)
return math.floor(x/60) .. ":" .. (x % 60 < 10 and "0" or "") .. x % 60
end
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
1 comment
If you have more than four conditions in an if statement, you should probably revise your script logic.