So, I made this script that works:
local time = 120 for i = 1, 120 do wait(1) time = time - 1 script.Parent.Text = tostring(time) end
But when you die, the whole clock resets. Can somebody add a line that makes it so it doesn't reset? Thanks!
Original Answer
The easiest way I can think of doing this would be to clone a GUI into every character that spawns, while keeping the time in a server script. Put this in a script that is in the workspace, and a gui in the script:
local gui = script.TextLabel -- This line assumes you have a TextLabel with the script as it's Parent, change it as you wish. local time = 120 for i = 1, 120 do wait(1) time = time - 1 end game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) gui:Clone().Parent = player.PlayerGui gui.Text = tostring(time) end) end)
You're countdown script will now count down from 120 to 0 once while putting a GUI on you're screen each time you re spawn.
Resetting and Reapplying
The best way to do this, in my opinion, would be to make the original countdown script itself a function. Then, when the function is called, it will start the countdown.
local gui = script.TextLabel -- This line assumes you have a TextLabel with the script as it's Parent, change it as you wish. local time = 120 function countdown() -- Declared the function 'countdown' for i = 1, 120 do wait(1) time = time - 1 end game.Players.PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) gui:Clone().Parent = player.PlayerGui gui.Text = tostring(time) if time == 0 then -- Checks if the countdown is done gui:Destroy() -- Add in an event you wish to happen when the countdown finishes here wait() time = 120 -- Resets the countdown end end) end) end countdown() -- Now every time this is called, it will run the function
Now, you can add on anything to this script and just call the function countdown when you want the countdown to start.
Put this code in the Gui
local time = tonumber(script.Parent.Text) for i = time, 0, -1 do wait(1) script.Parent.Text = tostring(i) end
And in a global script
for i = 120, 0, -1 do game.StarterGui.CLOCK.Text = i --or whatever its called wait(1) end