T- Countdown Support

Hi there! How would I create a T- countdown timer? Like this one for SpaceX’s starship launches.

Screenshot_43

I have the GUI all set. I just can’t figure out how to do the countdown with milliseconds. My countdown will start from 12 seconds. Thanks for any help!

Sorry I did not understand what you wanted to achieve, do you mean you want the countdown to be in milliseconds?

Edit: Sorry I did not read the post correctly, that was an error on my part, I’ll try and find a solution and get back to you

Alrighty! Thanks :slight_smile:

Hi!

I found already written script by @Amiaa16, and changed it only slightly. RunService.Heartbeat is deprecated since about 2 weeks, so I’ll find a better alternative and ping you. Use min, sec and mil variables to form your text.

local RunService = game:GetService("RunService")

local COUNTDOWN = 10

local min, sec, mil

repeat
	RunService.Heartbeat:Wait()

	COUNTDOWN -= 1/10

	min = math.floor(COUNTDOWN / 60)
	sec = COUNTDOWN - min *60
	mil = math.floor((sec - math.floor(sec)) * 10)
	sec = math.floor(sec)
	print(min .. ":" .. sec .. ":" .. mil, "total time has passed") 
until COUNTDOWN <= 0
COUNTDOWN = 10

EDIT @heeboss2136 I think it’s best if you combine both this and @AAD232007’s solution :slight_smile:

1 Like

Hi! Thanks. The problem with this is that it’s counting up and not down. How can I change this?

Ok, so a solution I thought of is that you could use a remote event to make this happen. How it’ll work is that you will first put an event inside of rep storage. Then, you will use a script inside of the ServerScriptService to fire all clients of that event (if you don’t understand what I mean, let me know and I can explain). Then, you’ll make two separate textLabels in the same GUI (doesn’t matter where), one to represent the time in seconds, and one to represent the time in milliseconds. I’m saying two GUI’s because I am understanding that you want the time in milliseconds to be a different color right? Finally, in each of the textLabels, insert a local script that says this:
For the time in seconds text Label:

local event = game.ReplicatedStorage:WaitForChild("YourEventName")
local parent = script.Parent
event.OnClientEvent:Connect(function()
	local holder = 12 -- Amount of seconds in your countdown
	while holder >= 0 do 
		parent.Text = holder
		wait(1)
		holder = holder - 1
	end

end)

Now for the time in Milliseconds text Label:

local event = game.ReplicatedStorage:WaitForChild("YourEventName")
local parent = script.Parent
event.OnClientEvent:Connect(function()
	local holder = 12 -- Amount of seconds in your countdown
	local number = 10
	while holder >= 0 do 
		while number >=0 do
			parent.Text = number
			wait(0.1)
			number = number - 1
		end
		holder = holder - 1
		number = 10
		
	end

end)

I tested this script and it works, though @EssenceExplorer 's script is probably more effective.

PS: For both of the holder variables inside both scripts, change those to be however many seconds your countdown is, doesn’t matter how many, but they have to be the same otherwise it won’t work.

1 Like

Thanks! Could you explain what you mean by firing the clients? Thanks a lot! And yes It would be awesome to have them in different colours so this helps!

Hello, I have a countdown script made by me but it doesn’t include milliseconds unfortunately. I can still forward it onto you if you would like.

1 Like

Ok, so to fire the client it will take less than 5 lines of code. Here in the serverSciptService, make a script (call it whatever you want), and this is how it should look like:

--[[Whatever code you want to run BEFORE the countdown starts run it here.
For example, if you wanted to wait for the plr to press a button or whatnot]]--
local event = game.ReplicatedStorage.YourEventName
wait(5) -- I'm just putting this wait so that the code doesn't run the moment a player joins.
event:FireAllClients()

The rest, you can follow as I said before, this is just the script for the one inside the SSS (Server script service)

Awesome! I’ll check out some of the other solutions first but if I need some help ill ask :slight_smile:

Also, if you need any more understanding of FireAllClients, visit this link, it explains it in detail.

@AAD232007 I appreciate your posts, but it seems worth to mention that wait() or wait(0.1) are not a good idea when it comes to precise countdown timers. wait(), as I keep repeating, is part of Roblox 30Hz pipeline, is based on pooling, and is not reliable or consistent. While RunService waits are event based, wait() yields. Delays may occur, with wait() being even ower 0.2 seconds or even more. Avoid it any time your work with loops.
As far as events go, be aware that delays will happen, and the server will see countdown finished way before any of the clients, because data has to travel over the network. It shouldn’t be much of a problem, however. Your :FireAllClients() model idea is a good one. Should you guys want to try and get close to synchonizing client and server times, consider implementing Time Sync from Quenty’s NeverMore Engine.

@heeboss2136 I’ve updated the code above, so you should now combine both.

1 Like

Yes, you are right, that is why I mentioned that the code that you made is more effective. I just made this code because it is more beginner related and easier to understand.

2 Likes

All runService stepped, render stepped, heartbeat are “deprecated”. But there’s no one choice currently, it’s only because they’re gonna replace them with better names and one extra option, but sadly that took a bit longer than anticipated, it will either get undeprecated, but it will work just fine with the old stuff. The new methods do not work.n

1 Like