How to make a countdown TextLabel?

I am currently making a traffic light and there needs to be a 30 second timer on the highlighted part image

This is the explorer:
image

4 Likes

You can make it so when a certain condition is met, it creates a numerical for loop that repeats 30 times, changing the text of the textlabel to the number it is at and waiting a second. Example, let’s say you have a script in the text label and you want it countdown on server creation, you could do:

for i = 30, 0, -1 do
   script.Parent.Text = tostring(i)
   wait(1)
end

To countdown from 30 seconds to 0

Full script?

uioyiouh7gt6yiyjgyjgygyj

That is not that full script, that is how you’d go about making a countdown, as you wanted. You have to include it with how you want to activate the countdown, we are not allowed to give full scripts

3 Likes

A very simple one would be:

local Timer = script.Parent
Timer.Text = 30
repeat
Timer.Text -= 1
wait(1)
until Timer.Text == "0"

That’s not working for me

guiuityilyoyy9u i

Where did you put this? Local script, server script? What is it parented to?

1 Like

In the text label put a server script:

while true do
    for i = 30,1,-1 do
        script.Parent.Text = i
        wait(1)
    end
    for i = 10,1,-1 do
        script.Parent.Text = i
        wait(1)
    end
end

Note: this script is for a 30 second countdown (red) then a 10 second countdown (green) then it repeats. You will have to adjust it accordingly.

A simple countdown would be:

for i = 30,1,-1 do
    script.Parent.Text = i
    wait(1)
end
1 Like

In a script parented by the TextLabel.

This make it so when you join it displays a random number between 0 and 30. Can you help fix it?

That’s because the countdown has started before you’re able to load into the game. You should put something at the start of the script so that the countdown only starts when you want it to.

It’s not, I spawned in and it said 7

It doesn’t countdown either way, it just stays on the number

How could I make it that it starts when a click detector is pressed?

Do you want it to be:

  • just click it and it starts
  • click it, after it ends click it again to start again
  • click it and it turns on, click it again to turn it off
  • other?

Click it and it starts and when it ends, click it again to restart it.

image

In the click detector put a script:

local textLabel = game.Workspace.Timer.SurfaceGui.TextLabel
script.Parent.MouseClick:Connect(function()
    script.Parent.MaxActivationDistance = 0
    for i = 30,0,-1 do
        textLabel.Text = i
        wait(1)
    end
    textLabel.Text = ""
    script.Parent.MaxActivationDistance = 10
end
1 Like

Where it says

Make sure to not copy it, but define it. If you don’t know how, you’ll have to show me your explorer.

What’s the problem here? image