Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

3 comments

0

hiimgoodpack, this page is about opposite counter, I am asking about normal counter

0

That's still applicable... Nobody should have to spoon feed you scripts that you don't understand.

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.