How would I make this timer more efficient?
while true do local m = Instance.new("Message") player = game.Players:findFirstChild(hit.Parent.Name) m.Parent = player m.Text = "5:00 Left" wait(1) m.Text = "4:59 Left" wait(1) m.Text = "4:58 Left" wait(1) m.Text = "4:57 Left" wait(1) m.Text = "4:56 Left" wait(1) m.Text = "4:55 Left" wait(1) m.Text = "4:54 Left" wait(1) m.Text = "4:53 Left" wait(1) m.Text = "4:52 Left" wait(1) m.Text = "4:51 Left" wait(1) m.Text = "4:50 Left" wait(1) m.Text = "4:49 Left" wait(1) m.Text = "4:48 Left" wait(1) m.Text = "4:47 Left" wait(1) m.Text = "4:46 Left" wait(1) m.Text = "4:45 Left" wait(1) m.Text = "4:44 Left" wait(1) m.Text = "4:43 Left" wait(1) m.Text = "4:42 Left" wait(1) m.Text = "4:41 Left" wait(1) m.Text = "4:40 Left" wait(1) m.Text = "4:39 Left" wait(1) m.Text = "4:38 Left" wait(1) m.Text = "4:37 Left" wait(1) m.Text = "4:36 Left" wait(1) m.Text = "4:35 Left" wait(1) m.Text = "4:34 Left" wait(1) m.Text = "4:33 Left" wait(1) m.Text = "4:32 Left" wait(1) m.Text = "4:31 Left" wait(1) m.Text = "4:30 Left" wait(1) m.Text = "4:29 Left" wait(1) m.Text = "4:28 Left" wait(1) m.Text = "4:27 Left" wait(1) m.Text = "4:26 Left" wait(1) m.Text = "4:25 Left" wait(1) m.Text = "4:24 Left" wait(1) m.Text = "4:23 Left" wait(1) m.Text = "4:22 Left" wait(1) m.Text = "4:21 Left" wait(1) m.Text = "4:20 Left" wait(1) m.Text = "4:19 Left" wait(1) m.Text = "4:18 Left" wait(1) m.Text = "4:17 Left" wait(1) m.Text = "4:16 Left" wait(1) m.Text = "4:15 Left" wait(1) m.Text = "4:14 Left" wait(1) m.Text = "4:13 Left" wait(1) m.Text = "4:12 Left" wait(1) m.Text = "4:11 Left" wait(1) m.Text = "4:10 Left" wait(1) m.Text = "4:09 Left" wait(1) m.Text = "4:08 Left" wait(1) m.Text = "4:07 Left" wait(1) m.Text = "4:06 Left" wait(1) m.Text = "4:05 Left" wait(1) m.Text = "4:04 Left" wait(1) m.Text = "4:03 Left" wait(1) m.Text = "4:02 Left" wait(1) m.Text = "4:01 Left" wait(1) m.Text = "4:00 Left" wait(1) m.Text = "3:59 Left" wait(1) m.Text = "3:58 Left" wait(1) m.Text = "3:57 Left" wait(1) m.Text = "3:56 Left" wait(1) m.Text = "3:55 Left" wait(1) m.Text = "3:54 Left" wait(1) m.Text = "3:53 Left" wait(1) m.Text = "3:52 Left" wait(1) m.Text = "3:51 Left" wait(1) m.Text = "3:50 Left" wait(1) m.Text = "3:49 Left" wait(1) m.Text = "3:48 Left" wait(1) m.Text = "3:47 Left" wait(1) m.Text = "3:46 Left" wait(1) m.Text = "3:45 Left" wait(1) m.Text = "3:44 Left" wait(1) m.Text = "3:43 Left" wait(1) m.Text = "3:42 Left" wait(1) m.Text = "3:41 Left" wait(1) m.Text = "3:40 Left" wait(1) m.Text = "3:39 Left" wait(1) m.Text = "3:38 Left" wait(1) m.Text = "3:37 Left" wait(1) m.Text = "3:36 Left" wait(1) m.Text = "3:35 Left" wait(1) m.Text = "3:34 Left" wait(1) m.Text = "3:33 Left" wait(1) m.Text = "3:32 Left" wait(1) m.Text = "3:31 Left" wait(1) m.Text = "3:30 Left" wait(1) m.Text = "3:29 Left" wait(1) m.Text = "3:28 Left" wait(1) m.Text = "3:27 Left" wait(1) m.Text = "3:26 Left" wait(1) m.Text = "3:25 Left" wait(1) m.Text = "3:24 Left" wait(1) m.Text = "3:23 Left" wait(1) m.Text = "3:22 Left" wait(1) m.Text = "3:21 Left" wait(1) m.Text = "3:20 Left" wait(1) m.Text = "3:19 Left" wait(1) m.Text = "3:18 Left" wait(1) m.Text = "3:17 Left" wait(1) m.Text = "3:16 Left" wait(1) m.Text = "3:15 Left" wait(1) m.Text = "3:14 Left" wait(1) m.Text = "3:13 Left" wait(1) m.Text = "3:12 Left" wait(1) m.Text = "3:11 Left" wait(1) m.Text = "3:10 Left" wait(1) m.Text = "3:09 Left" wait(1) m.Text = "3:08 Left" wait(1) m.Text = "3:07 Left" wait(1) m.Text = "3:06 Left" wait(1) m.Text = "3:05 Left" wait(1) m.Text = "3:04 Left" wait(1) m.Text = "3:03 Left" wait(1) m.Text = "3:02 Left" wait(1) m.Text = "3:01 Left" wait(1) m.Text = "3:00 Left" wait(1) m.Text = "2:59 Left" wait(1) m.Text = "2:58 Left" wait(1) m.Text = "2:57 Left" wait(1) m.Text = "2:56 Left" wait(1) m.Text = "2:55 Left" wait(1) m.Text = "2:54 Left" wait(1) m.Text = "2:53 Left" wait(1) m.Text = "2:52 Left" wait(1) m.Text = "2:51 Left" wait(1) m.Text = "2:50 Left" wait(1) m.Text = "2:49 Left" wait(1) m.Text = "2:48 Left" wait(1) m.Text = "2:47 Left" wait(1) m.Text = "2:46 Left" wait(1) m.Text = "2:45 Left" wait(1) m.Text = "2:44 Left" wait(1) m.Text = "2:43 Left" wait(1) m.Text = "2:42 Left" wait(1) m.Text = "2:41 Left" wait(1) m.Text = "2:40 Left" wait(1) m.Text = "2:39 Left" wait(1) m.Text = "2:38 Left" wait(1) m.Text = "2:37 Left" wait(1) m.Text = "2:36 Left" wait(1) m.Text = "2:35 Left" wait(1) m.Text = "2:34 Left" wait(1) m.Text = "2:33 Left" wait(1) m.Text = "2:32 Left" wait(1) m.Text = "2:31 Left" wait(1) m.Text = "2:30 Left" wait(1) m.Text = "2:29 Left" wait(1) m.Text = "2:28 Left" wait(1) m.Text = "2:27 Left" wait(1) m.Text = "2:26 Left" wait(1) m.Text = "2:25 Left" wait(1) m.Text = "2:24 Left" wait(1) m.Text = "2:23 Left" wait(1) m.Text = "2:22 Left" wait(1) m.Text = "2:21 Left" wait(1) m.Text = "2:20 Left" wait(1) m.Text = "2:19 Left" wait(1) m.Text = "2:18 Left" wait(1) m.Text = "2:17 Left" wait(1) m.Text = "2:16 Left" wait(1) m.Text = "2:15 Left" wait(1) m.Text = "2:14 Left" wait(1) m.Text = "2:13 Left" wait(1) m.Text = "2:12 Left" wait(1) m.Text = "2:11 Left" wait(1) m.Text = "2:10 Left" wait(1) m.Text = "2:09 Left" wait(1) m.Text = "2:08 Left" wait(1) m.Text = "2:07 Left" wait(1) m.Text = "2:06 Left" wait(1) m.Text = "2:05 Left" wait(1) m.Text = "2:04 Left" wait(1) m.Text = "2:03 Left" wait(1) m.Text = "2:02 Left" wait(1) m.Text = "2:01 Left" wait(1) m.Text = "2:00 Left" wait(1) m.Text = "1:59 Left" wait(1) m.Text = "1:58 Left" wait(1) m.Text = "1:57 Left" wait(1) m.Text = "1:56 Left" wait(1) m.Text = "1:55 Left" wait(1) m.Text = "1:54 Left" wait(1) m.Text = "1:53 Left" wait(1) m.Text = "1:52 Left" wait(1) m.Text = "1:51 Left" wait(1) m.Text = "1:50 Left" wait(1) m.Text = "1:49 Left" wait(1) m.Text = "1:48 Left" wait(1) m.Text = "1:47 Left" wait(1) m.Text = "1:46 Left" wait(1) m.Text = "1:45 Left" wait(1) m.Text = "1:44 Left" wait(1) m.Text = "1:43 Left" wait(1) m.Text = "1:42 Left" wait(1) m.Text = "1:41 Left" wait(1) m.Text = "1:40 Left" wait(1) m.Text = "1:39 Left" wait(1) m.Text = "1:38 Left" wait(1) m.Text = "1:37 Left" wait(1) m.Text = "1:36 Left" wait(1) m.Text = "1:35 Left" wait(1) m.Text = "1:34 Left" wait(1) m.Text = "1:33 Left" wait(1) m.Text = "1:32 Left" wait(1) m.Text = "1:31 Left" wait(1) m.Text = "1:30 Left" wait(1) m.Text = "1:29 Left" wait(1) m.Text = "1:28 Left" wait(1) m.Text = "1:27 Left" wait(1) m.Text = "1:26 Left" wait(1) m.Text = "1:25 Left" wait(1) m.Text = "1:24 Left" wait(1) m.Text = "1:23 Left" wait(1) m.Text = "1:22 Left" wait(1) m.Text = "1:21 Left" wait(1) m.Text = "1:20 Left" wait(1) m.Text = "1:19 Left" wait(1) m.Text = "1:18 Left" wait(1) m.Text = "1:17 Left" wait(1) m.Text = "1:16 Left" wait(1) m.Text = "1:15 Left" wait(1) m.Text = "1:14 Left" wait(1) m.Text = "1:13 Left" wait(1) m.Text = "1:12 Left" wait(1) m.Text = "1:11 Left" wait(1) m.Text = "1:10 Left" wait(1) m.Text = "1:09 Left" wait(1) m.Text = "1:08 Left" wait(1) m.Text = "1:07 Left" wait(1) m.Text = "1:06 Left" wait(1) m.Text = "1:05 Left" wait(1) m.Text = "1:04 Left" wait(1) m.Text = "1:03 Left" wait(1) m.Text = "1:02 Left" wait(1) m.Text = "1:01 Left" wait(1) m.Text = "1:00 Left" wait(1) m.Text = "0:59 Left" wait(1) m.Text = "0:58 Left" wait(1) m.Text = "0:57 Left" wait(1) m.Text = "0:56 Left" wait(1) m.Text = "0:55 Left" wait(1) m.Text = "0:54 Left" wait(1) m.Text = "0:53 Left" wait(1) m.Text = "0:52 Left" wait(1) m.Text = "0:51 Left" wait(1) m.Text = "0:50 Left" wait(1) m.Text = "0:49 Left" wait(1) m.Text = "0:48 Left" wait(1) m.Text = "0:47 Left" wait(1) m.Text = "0:46 Left" wait(1) m.Text = "0:45 Left" wait(1) m.Text = "0:44 Left" wait(1) m.Text = "0:43 Left" wait(1) m.Text = "0:42 Left" wait(1) m.Text = "0:41 Left" wait(1) m.Text = "0:40 Left" wait(1) m.Text = "0:39 Left" wait(1) m.Text = "0:38 Left" wait(1) m.Text = "0:37 Left" wait(1) m.Text = "0:36 Left" wait(1) m.Text = "0:35 Left" wait(1) m.Text = "0:34 Left" wait(1) m.Text = "0:33 Left" wait(1) m.Text = "0:32 Left" wait(1) m.Text = "0:31 Left" wait(1) m.Text = "0:30 Left" wait(1) m.Text = "0:29 Left" wait(1) m.Text = "0:28 Left" wait(1) m.Text = "0:27 Left" wait(1) m.Text = "0:26 Left" wait(1) m.Text = "0:25 Left" wait(1) m.Text = "0:24 Left" wait(1) m.Text = "0:23 Left" wait(1) m.Text = "0:22 Left" wait(1) m.Text = "0:21 Left" wait(1) m.Text = "0:20 Left" wait(1) m.Text = "0:19 Left" wait(1) m.Text = "0:18 Left" wait(1) m.Text = "0:17 Left" wait(1) m.Text = "0:16 Left" wait(1) m.Text = "0:15 Left" wait(1) m.Text = "0:14 Left" wait(1) m.Text = "0:13 Left" wait(1) m.Text = "0:12 Left" wait(1) m.Text = "0:11 Left" wait(1) m.Text = "0:10 Left" wait(1) m.Text = "0:09 Left" wait(1) m.Text = "0:08 Left" wait(1) m.Text = "0:07 Left" wait(1) m.Text = "0:06 Left" wait(1) m.Text = "0:05 Left" wait(1) m.Text = "0:04 Left" wait(1) m.Text = "0:03 Left" wait(1) m.Text = "0:02 Left" wait(1) m.Text = "0:01 Left" wait(1) m.Text = "0:00 Left" wait(1) m:Remove() end
Making a NumberValue is completely unnecessary: just use a for loop:
for i = 5*60, 0, -1 do m.Text = i wait(1) end
To display this using minutes, simply divide i
by 60. To get the remaining seconds, use the modulo operator:
m.Text = math.floor(i/60) .. ":" .. i%60
This has a problem, however: seconds less than 10 display only one digit, so let's add a simple if statement:
m.Text = math.floor(i/60) .. ":" if i%60 < 10 then m.Text = m.Text .. "0" .. i%60 else m.Text = m.Text .. i%60 end
Whoa, that's really inefficient...
Alright, so to make an efficient timer you would use a for loop:
ti = 120 --Two minutes while wait() do --A while do loop to repeat the contained code for i=ti,0,-1 do --A for loop that goes backwards from 120 to 0 m.Text = (i.." Seconds left") --Changing the text (I apologies, couldn't make it Minutes:SecondsInMinute) end end
References: For and while loop
Make a value, and do some math
m = Instance.new("Message") time = Instance.new("NumberValue") time.Value = "240" while wait() do wait(1) time.Value = time.Value - 1 m.Text = time.Value .. " Left"
Should work, but it will show the timer in seconds, not minutes and seconds