Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to create a timer that stops and resets itself when a value = 0?

Asked by 3 years ago

How can I create a timer that stops when a value = 0?

I want to make a timer where when a value = 0 then it resets the timer. Essentially when the value = 1 it starts the timer and counts down from 20 to 0 but if the value = 0 then it stops and resets the timer and doesn't count down. How can I go about doing this?

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Here's something that might help:

(Script)

value.Changed:Connect(function()
    if value.Value == 1 then
        for i = 20,0,-1 do
            timer.Value = i
        end
    elseif value.Value == 0 then
        timer.Value = 20
    end
end)

I don't know how the timer is set up, but right here I made it a value, which should be the case for a timer working in a server script and make a local script update the text of the timer.

I hope this helped!

Ad
Log in to vote
0
Answered by 3 years ago

Well I figured it out myself:

Script:

for i = 20,0,-1 do
            if value.Value >= 1 then
                    wait (1)
                timer.Value = i

            elseif value == 0 then
                timer.Value = 20
            end
                end 

Answer this question