While Loop not breaking when condition is met, Help is needed!

I removed the if statement already.


		    while debounce == true do
			
		    wait(.50)
		
		    Character.RobbedCash.Value = Character.RobbedCash.Value + 500
		            repeat wait(1) until Character.RobbedCash.Value >= 1000
				    print('true')
			        debounce = false
	        end

	end
	    
end)

You can turn this loop into a called function incase you need to call it again.

function StartLoop()
repeat
wait(0.50)
		
Character.RobbedCash.Value = Character.RobbedCash.Value + 500
until Character.RobbedCash.Value >= 1000

end

Also, if you need it to stop at a said value, why not use a for loop?

for i = 0, 1000, 500 do
wait(.5)
Character.RobbedCash.Value = Character.RobbedCash.Value + i
end

Check it inside of an if statement if it’s lower than 1000 then add their value by 500

Every time he would have to edit the code if he wants to increase the maximum and he would have to edit all of his code but I find this as the solution

He wouldn’t have to re-edit his code.

He can store the values as variables within the script then change them whenever he needs.

local Max1 = 1000
local Max2 = 1000

local ChosenMax

if thiscondition then
ChosenMax = Max1
elseif othercondition then
ChosenMax = Max2
end

for i = 0, ChosenMax, 500 do
wait(.5)
Character.RobbedCash.Value = Character.RobbedCash.Value + i
end
  for X = 0,MaxCash,500 do
			
		    wait(.60)
		
		    if Character.RobbedCash.Value < MaxCash then
		    Character.RobbedCash.Value = Character.RobbedCash.Value + X
 else
		    debounce = false
		    break
		    end
			
			end

	end
	    
end)

Using this but for some reason, as soon as it hits 500, the value goes to 1500 instead of 1000 and then breaks.

image

Here’s how it should look like:

local MaxCash = 1000

function UpdateCash()
 for i = 0, MaxCash, 500 do
  wait(.5)
  Character.RobbedCash.Value = Character.RobbedCash.Value + i
 end
end

You don’t need to break or run any checks as it will automatically stop once it reaches 1,000

It doesn’t stop when it reaches 1000.

  local function updateCash()
		   for X = 0, MaxCash, 500 do
			
		    wait(0.5)
		
		    Character.RobbedCash.Value = Character.RobbedCash.Value + X
		    debounce = false
		    end
			
			end
			updateCash()

	end
	    
end)

Because… you keep calling it from within the function so it’s constantly repeating itself…


function UpdateCash(MaxCash)
 for i = 0, MaxCash, 500 do
  wait(.5)
  Character.RobbedCash.Value = Character.RobbedCash.Value + i
 end
end

UpdateCash(1000)

This script will stop at 1000

1 Like

Maybe because you call the function again inside itself?

1 Like
  local function updateCash(MaxCash)
		   for X = 0, MaxCash, 500 do
			
		    wait(.5)
		
		    Character.RobbedCash.Value = Character.RobbedCash.Value + X
		    end
			
			end
			updateCash(1000)

	end
	    
end)

Still doesn’t stop. :frowning:

sigh… Just copy my script, Word for Word…

function UpdateCash(MaxCash)
 for i = 0, MaxCash, 500 do
  wait(.5)
  Character.RobbedCash.Value = Character.RobbedCash.Value + i
 end
end

UpdateCash(1000)

Doesn’t work either. (30 characters)

What’s the error in the console then…?

No errors in the console. (30 char)

Why are you calling the function again? Imagine you got a task, cut onions. You get a piece of paper with instructions. Paper reads:
-Cut onions
-Start the task again
Now you are stuck cutting onions for all eternity.

1 Like

Then. It should work. Unless…:
You haven’t called the function
or
You haven’t used my script
or
The “RobbedCash” Value doesn’t exist (but this would return an error so rule this one out)

Reading over it again, The “Character” Value isn’t defined either.

function UpdateCash(MaxCash, Character)
 for i = 0, MaxCash, 500 do
  wait(.5)
  Character.RobbedCash.Value = Character.RobbedCash.Value + i
 end
end

UpdateCash(1000, Char)

You get the character by other means.

Character value is defined, I just haven’t showed you the whole script and still same error.

Show me the entire script then, The code i have supplied for you should work. It will break when it reaches MaxCash.