I want to make this number to MM:SS string convert work with negatives, currently after reaching 0 it goes to 60 and starts counting down, however the original number stays as a negative. Here’s a video of the timer and the code:
Not sure what you’re asking here.. so:
Countdown to zero.
local Time = 10
local Digits = {Digit4, Digit3, Digit2, Digit1}
local function Convert(s)
local m = math.floor(s / 60)
local sec = s % 60
return string.format("%02d:%02d", m, sec)
end
while Time > 0 do
local NewTime = Convert(Time)
local chars = {string.sub(NewTime,1,1), string.sub(NewTime,2,2),
string.sub(NewTime,4,4), string.sub(NewTime,5,5)}
for i, digit in ipairs(Digits) do
digit.Image = Numbers:FindFirstChild(chars[i]).Texture
end Time -= 1
task.wait(1)
end
Reformat the negatives.
local Times = {10, -10, -1}
local Digits = {Digit4, Digit3, Digit2, Digit1}
local function Convert(s)
local neg = s < 0
s = math.abs(s)
local m = math.floor(s / 60)
local sec = math.floor(s % 60)
return neg, string.format("%02d:%02d", m, sec)
end
for _, Time in ipairs(Times) do
local neg, NewTime = Convert(Time)
local chars = {string.sub(NewTime,1,1), string.sub(NewTime,2,2),
string.sub(NewTime,4,4), string.sub(NewTime,5,5)}
for i, digit in ipairs(Digits) do
digit.Image = Numbers:FindFirstChild(chars[i]).Texture
end
Frame.Negative.Visible = neg
print(NewTime)
task.wait(1)
end
Also, please don’t post a picture of a script. Use the </> option to post formatted code.
This is my first post lol, anyways what i meant is when the timer goes below 0 to negative it completely breaks and goes to negative 60 and counts up, i want a fix for that so it doesnt break
Once counts down to zero (no fail).. the other formats the negative so it shows right.. one of them should be what you want.
