While value>0 do loop not printing anything

I am honestly a bit confused here.
I won’t make this very long cause 1) there’s not alot to it
and 2) it might be me who missed an obvious detail.

I have this little code right here to test what was wrong with the while loop, as it wasn’t working in my script:
image

It prints what I change the “test” value to, so I can see that it is detectable, which it was, as it printed 5.
But then the loop was supposed to constantly print “yes” every second when the test value is higher than 0, which we can see it clearly is.
But it did not print anything, so something is stopping the loop from running.

Does anybody know why this is happening?
From what I can see in this example of it here, the code should be working?

How is the value being set? If it’s not above 0 from when the script gets ran, then the loop will not start.

The value gets changed from a different server-script.

Oh, so when it is 0 or below, it stops permanently?

How would I make it stop and start depending on the value then?
Will I have it make it run on a while true do loop and constantly check what the value is?

You can just start the loop when it gets changed to above 0, and break it when you want to.

1 Like

Yes, depending on how your system is setup you could wait for it to get changed first:

local test = script.Parent:WaitForChild("FireTimer", 10)
test.Changed:Wait()

while test.Value > 0 do
	wait(1)
	print("yes")
end

But if you want it to reset once it reaches 0 then it gets a bit more complicated:

local test = script.Parent:WaitForChild("FireTimer", 10)

local function ConnectListener()
	local connection
	connection = test:GetPropertyChangedSignal("Value"):Connect(function()
		connection:Disconnect()
		
		print("Start")
		while (test.Value > 0) do
			print(test.Value)
			
			test.Value = test.Value - 1
			wait(1)
		end
		print("Finish")
		
		ConnectListener()
	end)
end

ConnectListener()

The loop is going to fire whenever the value is above 0, and then the thought was to minus the number by one every second until it reaches 0 again, while it will then “rest” and wait until another script adds to the number again.

It is for a fire effect. When you get hit with fire, the value goes up, then it slowly goes down every second, and once it reaches 0, it should stop. (And the fire would be put out.)

Oh. I will try that out!

The code you sent made it double every time, as for every time a loop changed the value, it created a new loop that did the same.

But it inspired me to make this:

image

And it seems to work?
So I take that as a solution lol!
Thanks! :slight_smile:

Ah, I updated my answer after you replied since there was a few issues with it (as you saw). Could you perhaps check if that fixed it?

Good that it got solved either way.

1 Like

Oh! Yes, I will check it out!

Yes, but I’ll see if your way might be better!