Making a number go down is simple, you could use a NumberValue and TweenService and make the tween decrease the number from how much to 0.
Or you could use a numeric for loop, the start being how much & the end being 0. You won’t need to include the increment as the default is 0.
Firing all the clients to see the change could be very inefficient, instead I’d say use a StringValue which is situated inside ReplicatedStorage.
Then inside the gui have a LocalScript which connects on .Changed of this StringValue and sets the new value to the gui. Remember that the parameter is the new value if the .Changed event is on a ValueBase.
There are many ways to do this. If you want an absolute beginner’s way to do this, refer to the post above your own. The solutions to your problems are being posted: take some time to digest the information and apply it to your system.
Keep the seconds value in an IntValue in ReplicatedStorage. When the server is modifying time, make it set the value of that IntValue. The client will then connect to the Changed event of the IntValue object and format the time using my code sample above.
In your Gui, wherever you have that time TextLabel placed, you will assign its text to the timeString variable.
Trouble in what sense? Details are required to actually address the issues you’re having. Have you actually read the posts and tried applying them to your work? What does your current implementation look like? Share the code responsible for counting down and formatting.
Considering what you said in the OP,
I made the assumption that you knew how to count down a timer, whatever control means. I’ve given the answer for this several times over now.
Handle your game time in seconds in any regard. When it comes to clients needing to.display that time, apply my formatting code. Don’t copy and paste it; actually modify it so it fits your system. Do some debugging on your own as well.
You don’t figure it out. It’s meant to be a formatting example. Nowhere in this code is there anything in regards to counting down, tbe expectation was that you filled that out yourself.
Start your game timer at a certain amount of seconds. If you don’t know what minute-to-second conversion is, take a number for minutes and multiply it by 60 to get a representation of minutes in seconds (6*60 - 360 seconds). Count this number down and store it in an IntValue. He the client to connect to it’s Changed event and then apply my formatting code. Use the string you get at the timeString variable and set it as the text of the TextLabel.
-- Server (Script, ServerScriptService)
local gameTime = 6*60
local tracker = Instance.new("IntValue")
tracker.Name = "GameTime"
tracker.Parent = game:GetService ("ReplicatedStorage")
-- Artificial initial buffer
wait(1)
while gameTime > 0 do
gameTime = gameTime - 1
tracker.Value = gameTime
wait(1)
end
--[[ With a for loop instead of a while loop
for i = gameTime, 0, -1 do
tracker.Value = i
wait(1)
end
--]]
-- Client (LocalScript, StarterPlayerScripts)
local tracker = game:GetService("ReplicatedStorage"):WaitForChild("GameTime")
tracker.Changed:Connect(function (newTime)
local minutes, seconds = math.floor(newTime/60), newTime%60
local timeString = string.format("%d:%.2d", minutes, seconds)
-- Up to you to figure this out
(TextLabelPathHere).Text = timeString
end)
I should not really have had to provide that for for you, as all the posts here have explained how to do this several times over. If you aren’t familiar with programming or don’t understand, please ask questions about the post rather than trying to ask for the code to make this work.
You should also put some (or more) time into learning how to code so these small issues can be resolved by yourself. Searching before posting is also important; there are many helpful finds on the DevForum, Developer Hub and the Toolbox.
This is as far as I’m willing to handhold, with the code above. Anything further, please refer to my posts as I have explained this process at least three times now. I won’t a fourth time.
It initialises a variable, gameTime, which represents your game time - the intention is in the variable name. It does a quick equation to resolve minutes to seconds by the formula n*60.
Assuming you don’t make your own value, it makes a tracker in ReplicatedStorage that the game time gets assigned to. This object is replicated to the client without the use of remotes, so we can directly access the time value.
The artificial buffer is just part of the sample code that waits one second before starting the game loop. Then, while the time is not 0, it counts down. There is an alternative version commented out that works with a numeric for loop.
Now, we move to the client-side.
The client listens for every change to the value and then gets what the IntValue’s value was changed to. We then apply formatting to that number and set the Gui’s text to that formatted string. The explanation for the string formatting, I have already provided before.
Please read this carefully and apply it to create a system. This is merely sample code, you are not supposed to use this whole thing as the basis for your game. If anything breaks with this code, that’s on you.
Do some debugging then. I have warned you that this is sample code and should not be used as the basis for your game. I am not going to hold your hand through this process either. The posts above provide significant information: it is up to you to interpret it. Not just mine, but everyone else’s.
Yes. When working with time in scripts, often you will either be using seconds or milliseconds depending on your circumstances. The code samples I’ve provided in this thread work in seconds.