Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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 :)

1 comment

0

The Countdown starts without me doing anything (when I join the game it starts immediately).

This discussion is preserved as it was. New answers, comments, and votes are closed.