While true do completely stops

Hello, basically this while true do() is completely stopping and won’t restart as I put in “break”. If I print something, it keeps going on and on, how do I make the loop STOP but also restart once the value has changed again.

The script:

while true do
	wait(1)
	if carryon2 == false then
		script.Parent.Value.Value -= 1
		if script.Parent.Value.Value == 0 then
			script.Parent.gangName.Value = game.Players:FindFirstChild(playerName).gangSystem.gangName.Value
			script.Parent.BillboardGui.TextLabel.Text = game.Players:FindFirstChild(playerName).gangSystem.gangName.Value
			script.Parent.BillboardGui.TextLabel.TextColor3 = game.Players:FindFirstChild(playerName).gangSystem.gangColour.Value
			break
		end
	end

	if carryon2 == true then
		print("err")
	end
end

In basic words, it only works once.

Because you break the loop possibly?

script.parent.Value.Value -= 1 -- Would go to 0 if your value is 1

if (script.Parent.Value.Value == 0) then
 
 break
end

One way would be to add it to a function and when you need to run it just call the function. Also could you not have the true part of the loop set to script.Parent.Value.Vaue== 0 rather then using the break.

2 Likes

Then the loop is pointless there’s a break after that. Why not use carryon2 == false

Unfortunately, none of these solutions work.

That’s because there’s a break.

I realised, but I am here to find out what I should use instead.

Like what @LifeDigger said use a function:

2 Likes

incorrect, here is the fixed script:

while true do
	wait(1)
	if carryon2 == false then
		script.Parent.Value.Value -= 1
		if script.Parent.Value.Value == 0 then
			script.Parent.gangName.Value = game.Players:FindFirstChild(playerName).gangSystem.gangName.Value
			script.Parent.BillboardGui.TextLabel.Text = game.Players:FindFirstChild(playerName).gangSystem.gangName.Value
			script.Parent.BillboardGui.TextLabel.TextColor3 = game.Players:FindFirstChild(playerName).gangSystem.gangColour.Value
			break
		end
	end

	if carryon2 == true then
		print("err")
	end
end

Alright, I will give that a go.

That still stops the loop… There’s still a break

She’s trolling, I flagged her just ignore her.

3 Likes

i have an idea, use a boolvalue and detect when the numver value is below 0, when it is set it to true, then do an if statement check in teh while true

It’s pointless how would the value update if there’s no loop to change it.

value.Changed:Connect(function()
    if value.Value <0 then
     boolvalue = true
end

I used a function and it works now, I appreciate it.

2 Likes

Well he wants to break the loop as said in his post “How do I make the loop stop but also restart once the value has changed again”. So he’s obviously changing it elsewhere too.

To restart the loop just call the function via :GetPropertyChangedSignal

you can literally just do value.Changed

No the value change inside the loop just look at the script: