Continuing Functions from Loops

I have a function here and I was wondering how you would make this run while activating the loop and continuing without the loop holding the function. I have tried adding continue but that seems just to stop everything. I have just been stuck.

sound:Play()
wait(3)
bar.Transparency = 0 
for i = 1, 20 do
	doorLight.Material = 'Neon'
	doorLight.Color = Color3.fromRGB(255, 0, 0)
	wait(.4)
	doorLight.Material = 'SmoothPlastic'
	doorLight.Color = Color3.fromRGB(99, 95, 98)
	wait(.4)
	continue
end
wait(1)
bar.Transparency = 1
lightSlider.Transparency = 0
wait()
tween:Play()

Use task.spawn()

task.spawn(function()
	for i = 1, 20 do
		doorLight.Material = Enum.Material.Neon
		doorLight.Color = Color3.fromRGB(255, 0, 0)
		task.wait(0.4)
		
		doorLight.Material = Enum.Material.SmoothPlastic
		doorLight.Color = Color3.fromRGB(99, 95, 98)
		task.wait(0.4)
	end
end)
2 Likes

Task library is new and an improved version of a few functions like wait, spawn etc.