local TimeStampInSeconds = 600
repeat
for i = 1, TimestampInSeconds do
local Timestamp = (DateTime.fromUnixTimestamp(TimestampInSeconds):FormatUniversalTime("mm:ss", "pt-br"))
task.wait(1)
TimestampInSeconds -= 1
Status.Value = "In-game: "..Timestamp
end
until TimestampInSeconds == 0
This timestamp works correctly, but sometimes it glitches coming back to an old timestamp. Sometimes it’s at 5:12, then randomly comes back at 5:17, then 5:11 (all in one second). Can someone help me?
Are you sure there is no more scripts or threads running that affect that value?
Tbh I never used DateTime.fromUnixTimestamp, why not just do this using math?
And you don’t need to wrap your for loop into another loop. Script surely counts down to 0. You can modify it a bit so you don’t need to decrement original value.
local TimeStampInSeconds = 600
local function TimeToString(TimeStamp)
local Minutes = math.floor(TimeStamp / 60)
local Seconds = math.floor(TimeStamp % 60)
return (Minutes < 10 and "0") or ""..Minutes..":"..(Seconds < 10 and "0") or ""..Seconds
end
for TimeLeft = TimeStampInSeconds, 0, -1 do
local Timestamp = TimeToString(TimeLeft)
print("In-game: "..Timestamp)
end
I feel stupid about this… Sorry.
I added back the task.wait. Try it.
local TimeStampInSeconds = 600
local function TimeToString(TimeStamp)
return ("%.2d:%.2d"):format(math.floor(TimeStamp / 60), math.floor(TimeStamp % 60))
end
for TimeLeft = TimeStampInSeconds, 0, -1 do
local Timestamp = TimeToString(TimeLeft)
Status.Value = "In-game: "..Timestamp
task.wait(1)
end
That means the script runs two times, did you connect this function to PlayerAdded? You should run it only once, or check if it’s not running already