How do i fix that thing " Script timeout: exhausted allowed execution time "

  1. What do you want to achieve? Keep it simple and clear!
    I wanna achieve my script works, but i start lagging at one moment and then get that error

  2. What is the issue? Include screenshots / videos if possible!
    i alr wrote issue in title lol

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I didn’t find anything.

Here is code

local MoneyLevel = script.Parent.Parent.Parent.MoneyLevel
local SpeedLevel = script.Parent.Parent.Parent.SpeedLevel
local MainPart = script.Parent.Parent.MainPart
local FactoryBrokenValue = script.Parent.Parent.FactoryBroken
local DB = true
while DB == true do
	while MoneyLevel.Value == 0 do
		while SpeedLevel.Value == 0 do
			while FactoryBrokenValue.Value == false do
				wait(0.8)
				script.Parent.Position = Vector3.new(42.434, 10.85, -335.235)
				local PlrBricks = script.Parent.Parent.Parent.PlayerBricks
				PlrBricks.Value = PlrBricks.Value + 1
				script.Parent.Anchored = true
				script.Parent.Transparency = 1
				wait(3)
				script.Parent.Anchored = false
				script.Parent.Transparency = 0
			end
		end
	end
	while SpeedLevel.Value == 1 do
		while MoneyLevel.Value == 0 do
			while FactoryBrokenValue.Value == false do
				wait(0.8)
				script.Parent.Position = Vector3.new(42.434, 10.85, -335.235)
				local PlrBricks = script.Parent.Parent.Parent.PlayerBricks
				PlrBricks.Value = PlrBricks.Value + 1
				script.Parent.Anchored = true
				script.Parent.Transparency = 1
				wait(2)
				script.Parent.Anchored = false
				script.Parent.Transparency = 0
			end
		end
	end	
while SpeedLevel.Value == 1 do
		while MoneyLevel.Value == 1 do
			while FactoryBrokenValue.Value == false do
				wait(0.8)
				script.Parent.Position = Vector3.new(42.434, 10.85, -335.235)
				local PlrBricks = script.Parent.Parent.Parent.PlayerBricks
				PlrBricks.Value = PlrBricks.Value + 2
				script.Parent.Anchored = true
				script.Parent.Transparency = 1
				wait(2)
				script.Parent.Anchored = false
				script.Parent.Transparency = 0
			end
		end
	end
	end

You have some logic problems in the script, nesting while loops like that wont work like it does for if statements, if the inner loop quits but an outer loop doesn’t the script gets stuck forever, which is what causes the error

The reason you’re getting such issues is because you’ve put while loops in while loops. Not only is this running them a ridiculous amount of time, using a lot of power and memory, it’s also running through loops which have no pauses. For example, if the inner loop isn’t working then all the others run for an indefinite amount of time without pauses, checking values.

You could just use Changed events and not 7 while loops.

PS: task.wait() is better for waiting.

I tryed use changed events, this won’t help because when factory isn’t broken in first time, script which give money is just stop

so it’s need to break atleast one time to work

So if there is way to make other detect of value?