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

How to make a Gui Countdown efficiently?

Help? I am trying to make it so when the soundId changes, on the button it will count down from 125 on the scripts parents text. This wont work?

function onChanged()
	
local Time = 125
for i = Time, 0, -1 do
Time = i
wait(1)
end
script.Parent.Text = tostring(Time)
end

script.Parent.Parent.ScrollingFrame.Sound.SoundId:connect(Changed)

2 answers

Haven't tested but im pretty sure I didnt make any errors

local CountDownFrom = 125

script.Parent.MouseButton1Click:connect(function()
	for i = 0,CountDownFrom,1 do
		script.Parent.Text = CountDownFrom - i
		wait(1)
	end
end)

for on Sound Id Change (didnt test this one either)

local CountDownFrom = 125

script.Parent.Parent.ScrollingFrame.Sound.SoundId.Changed:connect(function()
	for i = 0,CountDownFrom,1 do
		script.Parent.Text = CountDownFrom - i
		wait(1)
	end
end)

+1 pl0x?

6 comments

0

This works, Thanks. Altho I realized it would be an easier task if it was onChanged, How would you do that?

1

check my post i redid it for you and i didnt test make sure the location is correct and +1 pl0x?

0

Thanks, I cant +1 but I would if I could.

0

For some reason that's not working, Is onChange even a function?

0

is there an error + .Changed is an event and no thats not a function

0

There is no error as it says

Perhaps I'm mistaken, but I'm under the impression that you simply set the text to the given time on the wrong line -- You placed it after the loop...

script.Parent.MouseButton1Down:connect(function()
	local Time = 125
	for i = Time, 0, -1, do
		script.Parent.Text = tostring(Time)
		Time = i
		wait(1)
	end
end

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