How to delay for i do loop?

I have made a script where two conditions are met that the for i do loop gets executed.
but if i put wait() in the loop, the loop just completely breaks, anyone got an idea on how to delay this loop?

Heres the script:

local occupant = script.Parent.Parent.Car.Chassis:FindFirstChild("VehicleSeat")
local EngineLoud = script.Parent.EngineSound.WindAmbient1.DistortionSoundEffect
local isEnabled = false
local objects = {}


for i = 1, 10 do
  
  objects[i] = script.Parent.EngineSound["p" .. i] -- searches every particle emitter, the names are p1, p2, p3, p4, p5, p6, p7, p8, p9, p10
  
end



while task.wait() do
if occupant.Occupant and EngineLoud.Level >= 0.1 then
  -- Enable the p's using a for loop
    for i = 1, #objects do
    if objects[i] then
        objects[i].Enabled = true
        isEnabled = false
    end
  end
else
  -- Disable the p's
    for i = 1, #objects do
    if objects[i] then
        objects[i].Enabled = false
        
    end
  end
end
end

I would be very happy if you guys could tell me how i can make it delay like 5 seconds after each p has been enabled.

It would be something like this! You do not want to have the engine running when theirs no one in it. So you connect to the occupant changed value or whatever that is in your case and the condition of the loop is while occupant.Occupant do and disconnects when occupant is gone then reconnects when its occupied

occupant:GetPropertyChangedSignal("Occupant"):connect(function()
if occupant.Occupant~=nil then
while  occupant.Occupant do
task.wait()
if EngineLoud.Level>=.1 then
end
end
end)

No it has nothing to do with engine, my car has a button and that button makes the car faster (like a sport mode button) and the button also makes the DistortionSoundEffect 0.7 and if i get in my car the engine already runs(different script) so the script which i provided, will make a smoke effect on the engine, if both conditions are met (occupant and engineloud.level) then the smoke effect should be there, because the car runs faster i want an effect that like the engine overheats, now what i asked was is how do i put a delay after each p it enables in the for i loop?

The task.wait() may need to be adjusted to a more realistic value like
frame=(1/30)
task.wait(frame)

local occupant = script.Parent.Parent.Car.Chassis:FindFirstChild("VehicleSeat")
local EngineLoud = script.Parent.EngineSound.WindAmbient1.DistortionSoundEffect
local isEnabled = false
local objects = {}


for i = 1, 10 do
  
  objects[i] = script.Parent.EngineSound["p" .. i] -- searches every particle emitter, the names are p1, p2, p3, p4, p5, p6, p7, p8, p9, p10
  
end



while occupant.Occupant do --or use while true do
if occupant.Occupant and EngineLoud.Level >= 0.1 then
  -- Enable the p's using a for loop
    for i = 1, #objects do
    if objects[i] then
task.wait()
        objects[i].Enabled = true
        isEnabled = false
    end
  end
task.wait()--end of loop
else
  -- Disable the p's
    for i = 1, #objects do
    if objects[i] then
        task.wait()--wait per p
        objects[i].Enabled = false    
    end
  end
task.wait()--end of  for loop wait another frame
else task.wait() end
end

this would delay the script, but not the for i loop or would it? (not on my pc rightnow so i cant test it)

The loop always has a delay no matter what conditions are met. It waits per particle. in the for loop
if you want to turn them all on and wait just remove the waits in the for loop

local occupant = script.Parent.Parent.Car.Chassis:FindFirstChild("VehicleSeat")
local EngineLoud = script.Parent.EngineSound.WindAmbient1.DistortionSoundEffect
local isEnabled = false
local objects = {}


for i = 1, 10 do
  
  objects[i] = script.Parent.EngineSound["p" .. i] -- searches every particle emitter, the names are p1, p2, p3, p4, p5, p6, p7, p8, p9, p10
  
end



while occupant.Occupant do --or use while true do
if occupant.Occupant and EngineLoud.Level >= 0.1 then
  -- Enable the p's using a for loop
    for i = 1, #objects do
    if objects[i] then
--task.wait()
        objects[i].Enabled = true
        isEnabled = false
    end
  end
task.wait(EngineLoud.Level)--end of loop
else
  -- Disable the p's
    for i = 1, #objects do
    if objects[i] then
       -- task.wait()--wait per p
        objects[i].Enabled = false    
    end
  end
task.wait()--end of  for loop wait another frame
else task.wait() end
end

Hey there. I hope this works for ya!

local occupant = script.Parent.Parent.Car.Chassis:FindFirstChild("VehicleSeat")
local EngineLoud = script.Parent.EngineSound.WindAmbient1.DistortionSoundEffect
local isEnabled = false

local objects = {}


for i = 1, 10 do
	objects[i] = script.Parent.EngineSound["p" .. i] -- searches every particle emitter, the names are p1, p2, p3, p4, p5, p6, p7, p8, p9, p10
end


local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function(deltaTime)
	if occupant.Occupant and EngineLoud.Level >= 0.1 and isEnabled == false then
		for i = 1, #objects do
			if objects[i] and objects[i]:IsA("ParticleEmitter") then
				local Particles = objects[i]
				Particles.Enabled = true
				isEnabled = true
			end
		end
		task.wait(5)
		for i = 1, #objects do
			if objects[i] and objects[i]:IsA("ParticleEmitter") then
				local Particles = objects[i]
				Particles.Enabled = true
				isEnabled = false
			end
		end
	end
end)