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

How come my textbutton counter won't work at all?

Asked by 4 years ago

So I have a local script that when it's parents text is "00:30:00" it starts a countdown all the way to "00:00:00" and since this is the first time I tried making something like this it is just a ton of text and wait times due to me not knowing how to make a GUI text counter.

---Script---

local waittime = wait(1)
local frame = script.Parent.Text

if frame == "00:30:00" then
    local waittime
    frame = "00:29:00"
    local waittime
    frame = "00:28:00"
    local waittime
    frame = "00:27:00"
    local waittime
    frame = "00:26:00"
    local waittime
    frame = "00:25:00"
    local waittime
    frame = "00:24:00"
    local waittime
    frame = "00:23:00"
    local waittime
    frame = "00:22:00"
    local waittime
    frame = "00:21:00"
    local waittime
    frame = "00:20:00"
    local waittime
    frame = "00:19:00"
    local waittime
    frame = "00:18:00"
    local waittime
    frame = "00:17:00"
    local waittime
    frame = "00:16:00"
    local waittime
    frame = "00:15:00"
    local waittime
    frame = "00:14:00"
    local waittime
    frame = "00:13:00"
    local waittime
    frame = "00:12:00"
    local waittime
    frame = "00:11:00"
    local waittime
    frame = "00:10:00"
    local waittime
    frame = "00:9:00"
    local waittime
    frame = "00:8:00"
    local waittime
    frame = "00:7:00"
    local waittime
    frame = "00:6:00"
    local waittime
    frame = "00:5:00"
    local waittime
    frame = "00:4:00"
    local waittime
    frame = "00:3:00"
    local waittime
    frame = "00:2:00"
    local waittime
    frame = "00:1:00"
    local waittime
    frame = "00:00:00"
end
0
Did you get it working? royaltoe 5144 — 4y

3 answers

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

The frame variable contains the text inside the frame, not a reference to the frame's text property. If your frame contained the text "Hello World", the frame variable would be "Hello World"

When you change the contents of the frame variable, you're only changing the variable, not the frame's actual text.

You're going to have to make frame a reference to the frame and then change it's text property by saying frame.Text = "text goes here" and get the text by saying text = frame.Text

You can simplify your code by using loops:

local frame = script.Parent
startTime = 30

if(frame.Text == "00:30:00")then
    --count down from 30 to 0 every second, changing the text every time the loop runs. 
    for i = startTime, 0, -1 do
        if(i >= 10)then
            frame.Text = "00:" .. i .. ":00"
        else
            frame.Text = "00:0" .. i .. ":00"
        end
        wait(1)
    end
end
0
Did you manage to get it working? royaltoe 5144 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Please don't do a loop like that. Do something like this instead or do what the previous person did.

local seconds = script.Parent.Parent.Timer -- add a IntValue to the TextLabel/Button or ScreenGui and change the value to whatever time you want it to start at

script.Parent.Text = seconds.Value 

for i = 1,seconds.Value do
 wait(1)
 seconds.Value = seconds.Value - 1
 script.Parent.Text = seconds.Value
end

0
can u explain why he shouldn't do his code and do your code instead. you have the right idea but people can't learn without an explanation. also, he wants his text formatted like in his question. royaltoe 5144 — 4y
0
i appreciate you going out of your way to write a response and good job with the for loop royaltoe 5144 — 4y
0
^ Good point. You should do a loop like this, because it makes your code more organized and less of a hassle. It also helps the script function better by using the 'for i' statement so the script doesn't have to sit there and continuously execute code. I hope this helps. Tyler090130 619 — 4y
Log in to vote
0
Answered by
sngnn 274 Moderation Voter
4 years ago
Edited 4 years ago
local waittime = 30
local frame = script.Parent

for i = 1,waittime do
    frame.Text = "00:"..waittime..":00"
    waittime = waittime - 1
    if waittime < 10 then
        frame.Text = "00:0"..waittime..":00"
    end
    wait(1)
    end

This should work properly. If you need an explanation then the reason it's not working is because you're basically setting waittime to nothing by continuously using "local waittime." Use it only at the top to set it as the variable.

Answer this question