Timer doesn't stop and goes to negatives

I want to make a timer that repeats over and over but when it stops it creates a new round. Right now I am not doing the round thing.

The timer does not stop and it goes in negative numbers.

Script:

repeat
	wait(1)
	script.Parent.Text -= 1
until
script.Parent.Text == 0

Other script:

script.Parent.Changed:Connect(function()
	if script.Parent.Text == 0 then
		script.Parent.Text = 100
	end
end)
1 Like

Use a value.
I don’t suggest using 2 scripts for this.

Expanding on what I said about values;
Add a numerical value before the repeat loop runs.

local var = 0

You’ll be able to tick this counter up and use it with your repeat until loop. No need for another script.

The only thing I understood what you said was making a status bar. Is that all I need?

You could think of it like that.
What I mean is to have a variable in your script that’ll tick up, and once it hits a certain point, will end.
This’ll work well with your ‘repeat until’ loop

Example of what I mean:

local var = 0
repeat wait(1)
script.Parent.Text = var
var += 1
until
var == X (X is basically how long in seconds you want this to run)

This basically adds to the number value defined at line 1, which would represent time elapsed. Though, now that I think about it, os.time() or tick() could also be used. (albeit with more work)

This is what numeric for-loops are for.

[pseudocode]

while (true) do -- if you want to constantly reset
	startNewRound()
	for i = 100, 0, -1 do
		script.Parent.Text = i
		wait(1)
	end
end
2 Likes

I have no idea how this code is even working… shouldn’t this be throwing? OP’s trying to perform an arithmetic on a string value unless compound operators tonumber their operands or something. This code is incorrect at its root.

Ideally yes though, use a numeric for loop instead. It’ll stop iterating at the lower bound.

1 Like

It happens with all arithmetic operators. Lua(u) will call lua_tonumber on the operands if they are string representations of numbers.

="1" + "1" in the command bar will yield 11 2 because of the implicit casting to a number

However relational operators don’t do the same. ="1" == 1 yields false

I absolutely recommend for loops though, that is what they are for in this scenario

2 Likes

Everything else works but the timer won’t repeat.

I’d suggest using the code below mine, but if you want mine instead, reply with the current code you have.

I had the exact same problem a while back, just change this:

repeat
	wait(1)
	script.Parent.Text -= 1
until
script.Parent.Text == "0"

and

script.Parent.Changed:Connect(function()
	if script.Parent.Text == "0" then
		script.Parent.Text = 100
	end
end)

Since the text property is a string, not a number.