I need help with an issue

Hello!

I am back with another problem. (ik i have a lot of problems)
so I was scripting a fuel cell consumption system for my game and then I realized something.
normally the 4 fuel cells would all wait between 60-107 seconds and then they would go down by 1%
instead of doing so, it waits for the fuel cell before it to go down by 1% and then it does the same thing
you know, like it’s yielding
for example, fuel cell 2 wont wait the time specified and then go down by 1%. instead, it waits for fuel cell 1 to decrease by 1% and then it does it.

code
local monitor = ControlRoom.ReactorMonitor
	-- fuel cells
	task.spawn(function()
		while true do
			if module.ReactorActive == true then
				if module.OperationLevel == "normal" then
					if module.FuelCell1Level > 4 then
						task.wait(math.random(60, 107))
						module.FuelCell1Level -= 1
					end
					if module.FuelCell2Level > 4 then
						task.wait(math.random(60, 107))
						module.FuelCell2Level -= 1
					end
					if module.FuelCell3Level > 4 then
						task.wait(math.random(60, 107))
						module.FuelCell3Level -= 1
					end
					if module.FuelCell4Level > 4 then
						task.wait(math.random(60, 107))
						module.FuelCell4Level -= 1
					end
--- you can ignore the rest of the code
				elseif module.OperationLevel == "low" then
					if module.FuelCell1Level > 4 then
						task.wait(math.random(65, 113))
						module.FuelCell1Level -= 1
					end
					if module.FuelCell2Level > 4 then
						task.wait(math.random(65, 113))
						module.FuelCell2Level -= 1
					end
					if module.FuelCell3Level > 4 then
						task.wait(math.random(65, 113))
						module.FuelCell3Level -= 1
					end
					if module.FuelCell4Level > 4 then
						task.wait(math.random(65, 113))
						module.FuelCell4Level -= 1
					end
				elseif module.OperationLevel == "minimal" then
					if module.FuelCell1Level > 4 then
						task.wait(math.random(70, 120))
						module.FuelCell1Level -= 1
					end
					if module.FuelCell2Level > 4 then
						task.wait(math.random(70, 120))
						module.FuelCell2Level -= 1
					end
					if module.FuelCell3Level > 4 then
						task.wait(math.random(70, 120))
						module.FuelCell3Level -= 1
					end
					if module.FuelCell4Level > 4 then
						task.wait(math.random(70, 120))
						module.FuelCell4Level -= 1
					end
				end
				task.wait(.01)
			end
			task.wait(0.01)
		end
	end)

plz help
also you can ask for photos if you want

Thats what wait does it literally waits till the time specified and then it continues to the rest of the code what you want to do is use a debounce system or just have the code go through for all of them and just 1 wait function for all

Each time the script reaches the code line task.wait() it will yield the code for that long. In other words it completely stops running.
Move the task.wait(math.random(etc)) outside of the if statement. Either at the start or end of your loop.

1 Like

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