Loop not cancelling when it should

I am trying to use a while function and it is only supposed to go when 3 variables are false.

elseif firetype == 2 then
		if not firing or reloading or empty then
		
				
						firing = true
			repeat 
				shoot()
				
			until firing == false
			end

empty is supposed to be set to true when out of ammo and mags and is at the end of the Shoot() function
firing is set when clicked
reloading is set when reloading
when I use the tool with no more ammo it lags a lot and prints that it exhausted the execution time
I think this is because the loop is running while all of the if and elseif gates are false but the Print() at the end doesn’t fire.

No, its because you’re looping too much without waiting so it causes an exhaustion to stop overload or lag, do:

task.wait()

in the repeat section

elseif firetype == 2 then
		if not firing or reloading or empty then
		
				
						firing = true
			repeat 
				shoot()
				task.wait()
			until firing == false
			end
1 Like

In the function shoot() there is a wait block but ill try

Just remember I think the script still carries on looping even if the function is resumed or played so your task.wait() in the function by itself would be useless. Do task.wait(the total amount of wait you have in function), in the loop

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.