How to wait for something to happen within a infinite loop

I want to make the loop wait for the value to be less than or equal to zero.
I’ve tried return, but it does not work. If the value is less than zero before the 7.3 wait is over, the script works.
Any help would be appreciated greatly.
I also must keep this in the loop, as this is an automatic breach system.

	script.Parent.Sound.Playing = false
	script.Parent.Sound.Looped = false
	if tracker.Infected.Value <= 0 then

1 Like

repeat wait() until tracker.Infected.Value <= 0

Already did that, it does not work. It breaks the script entirely.

try using a boolean value to detect if its on or off

Yes but if the boolean value is false the script will just stop, there is no difference.

local debounce = false

    if not debounce and tracker.Infected.Value <= 0 then
        -- code here


debounce = true

try the check when the value has changed then check if its more than zero then run what you are trying to run

This will work in a loop?________________

1 Like

You can use renderstepped instead of a loop

i do not understand rendersteppped

Every frame that passes by, it runs the code

i don’t want it running the code every frame

well aren’t u doing that using a infinite loop?

No, I am not.

I’m confused on the issue a little bit. From what I can read, the script stops working if the value isn’t equal or less than 0 before the 7.3 seconds?

I know everything was confusing but I managed to make a different system using functions and values. Thank you for the help everyone.