Any tips on how I could make every part loop?

So I’m trying to make a light flickering system with the desired parts (tags) but when using while wait() do, it only runs one. I know it would happen, but is there any other way of using CS and this?

local CS = game:GetService("CollectionService")
for i, v in pairs(CS:GetTagged("Lights")) do
	print("I come from this path: ".. v:GetFullName())
	local aLight = v.SpotLight
	local light = v.Parent.Light
	local volume = light.LightSound.Volume
	while wait(1) do
		light.Transparency = 1
		aLight.Enabled = not aLight.Enabled
		volume = 0
		wait(0.1)
		light.Transparency = 0
		aLight.Enabled = not aLight.Enabled
		volume = 0.1
		wait(0.3)
		light.Transparency = 1
		aLight.Enabled = not aLight.Enabled
		volume = 0
		wait(math.random(0.1,0.5))
		light.Transparency = 0
		aLight.Enabled = not aLight.Enabled
		volume = 0.1
		wait(math.random(2,6))
		light.Transparency = 1
		aLight.Enabled = not aLight.Enabled
		volume = 0
		wait(0.1)
		light.Transparency = 0
		aLight.Enabled = not aLight.Enabled
		volume = 0.1
	end
end

Found the solution, task.spawn(function()

1 Like