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

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

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

1 comment

0

Did you get it working?

3 answers

✓ Accepted answer

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

1 comment

0

Did you manage to get it working?

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

3 comments

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.

0

i appreciate you going out of your way to write a response and good job with the for loop

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.

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.

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