Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I want to make a time counting script shorter, help?

Asked by 5 years ago
Edited 5 years ago

I want to make a time counting script with less words so that I can finish earlier. More specifically, the timer will never stop until a game is found.

Script:

local textLabel = script.Parent

textLabel.Text = "Looking for: 00:01"
wait(1)
textLabel.Text = "Looking for: 00:02"
wait(1)
textLabel.Text = "Looking for: 00:03"
wait(1)
textLabel.Text = "Looking for: 00:04"
wait(1)
textLabel.Text = "Looking for: 00:05"
wait(1)
textLabel.Text = "Looking for: 00:06"
wait(1)
textLabel.Text = "Looking for: 00:07"
wait(1)
textLabel.Text = "Looking for: 00:08"
wait(1)
0
hiimgoodpack, this page is about opposite counter, I am asking about normal counter SwingingMelons -18 — 5y
0
That's still applicable... Nobody should have to spoon feed you scripts that you don't understand. T0XN 276 — 5y

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
5 years ago

We can use a loop for this:

local waitedTime = 0

local function getFormattedTime(timeToFormat)
    local flooredTime = math.floor(timeToFormat)
    local minutes = math.floor(timeToFormat / 60)
    local seconds = math.floor(timeToFormat % 60)
    local formattedMinutes = minutes < 10 and "0" .. minutes or minutes
    local formattedSeconds = seconds < 10 and "0" .. seconds or seconds
    local formattedTime = formattedMinutes .. ":" .. formattedSeconds

    return formattedTime
end

while true do
    textLabel.Text = getFormattedTime(waitedTime)
    -- wait(1) will wait for at least a second, but could be for any time longer than that, so we simply add the return value, which is the time waited, to the total waited time
    waitedTime = waitedTime + wait(1)
end
Ad

Answer this question