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

How to make a Gui Countdown efficiently?

Asked by
NotSoNorm 777 Moderation Voter
10 years ago

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

Log in to vote
3
Answered by 10 years ago

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?

0
This works, Thanks. Altho I realized it would be an easier task if it was onChanged, How would you do that? NotSoNorm 777 — 10y
1
check my post i redid it for you and i didnt test make sure the location is correct and +1 pl0x? TochiWasHere 10 — 10y
0
Thanks, I cant +1 but I would if I could. NotSoNorm 777 — 10y
0
For some reason that's not working, Is onChange even a function? NotSoNorm 777 — 10y
View all comments (2 more)
0
is there an error + .Changed is an event and no thats not a function TochiWasHere 10 — 10y
0
There is no error as it says NotSoNorm 777 — 10y
Ad
Log in to vote
0
Answered by
saenae 318 Moderation Voter
10 years ago

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

Answer this question