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

How to create a countdown?

Screen Gui> - Holds all below in it.

  1. TextButton>Script - Script changes Value in TextButton named "Time" (NumberValue). - works
  2. Time(NumberValue) - Used by above for wait(Time)
  3. Count(NumberValue)>Script - Script changes Value of Count to Value of Time and Counts it down by doing -1 every 1 second (wait(1)) - doesn't work
  4. Countdown(TextLabel) - Text of it should show Count(NumberValue), a countdown - doesn't work.

Script for 3.Count (not working):

local IntermissionTime = script.Parent.Parent.Time

function Intermission()
	for i = IntermissionTime.Value, 0, -1 do
		script.Parent.Value = i
	end
end

Script for 4.Countdown (not working):

while true do wait(0.4)
if script.Parent.Parent.Parent.Visible == true then
	local sec = script.Parent.Parent.Parent.Parent.TextButton.Count
script.Parent.Text = ""..sec.Value.."s"

else print'no'
	end
end

Is there anyone who could help me with this? I can provide you with a model for this, so it's a lot easier to fix... I would really appreciate your time.

2 answers

Your first script didn't work because you didn't call the function, and you had no waits.

local intermissionTime = script.Parent.Parent.Time

function intermission()
	for secLeft = intermissionTime.Value, 0, -1 do
		script.Parent.Value = secLeft
		wait(1)
	end
end

intermission() --calls the function

And for your second script...

while wait() do
	if script.Parent.Parent.Parent.Visible then
		local sec = script.Parent.Parent.Parent.Parent.Parent.TextButton.Count
		script.Parent.Text = sec.Value.."s"
	else
		print("no")
	end
end

Those should work. If they don't, PM me on ROBLOX.

Like what AbstractMadness said, there is no wait. The problem is, he changed the Value not the text. With some editing, I made the script work! Also, all I edited was the text.

local intermissionTime = script.Parent.Parent.Time

for secLeft = intermissionTime.Value, 0, -1 do
        script.Parent.Text = secLeft.." seconds left!"
        wait(1)
    end
end

Hope this helps!

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