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

How can i start a timer when something on text label shows up?

Asked by
xPeyser 15
3 years ago

I tried this script:

if script.Parent.Parent.Text1.Text == "2" then
 while true do
    repeat 
        seconds = seconds - 1
        script.Parent.Text = tostring(seconds)
        wait(1)
    until seconds == 0
    script.Parent.Text = tostring("Teleporting Players...")
    wait(5)
    seconds = 26
end
end

This code is put in a script that is in a text label that is in a surface gui, and in that surface gui are 3 more text labels. The one i want to specify is "Text1". When Text1 shows up "2" i want that countdown script happen.

Pls help!

1 answer

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

Okay, I hope this can help you

First, try using the Changed event, as using an if statement just checks once. Then, this is not required, but why do you need to use tostring() on a string in line 8? It is already a string

script.Parent.Parent.Text1.Changed:Connect(function(property) -- replace if with changed
    if property == "Text" and script.Parent.Parent.Text1.Text == "2" then -- if the text changed, and if the text is "2" then
        while true do
            repeat
                seconds = seconds - 1
                script.Parent.Text = tostring(seconds)
                wait(1)
            until seconds == 0
            script.Parent.Text = "Teleporting Players..." -- why the tostring() ?
            wait(5)
            seconds = 26
        end
    end
end

Hope this helps :)

0
The Countdown starts without me doing anything (when I join the game it starts immediately). xPeyser 15 — 3y
Ad

Answer this question