In Pairs a Loop Delays the Next One Until the First One Is Finished

Recently, I was trying to make a flash appears on players’ screen when a player clicks a part but I was trying to make disappear gradually by editing BackgroundTransparency of it by a loop.

Here is my script:

function onClick (onClick)
for i,v in ipairs(game.Players:GetChildren()) do
	local flash = v.PlayerGui.Blindness.Frame
	for d = 0,1,0.01 do
		flash.BackgroundTransparency = d
		wait()
	end
	
end

end

script.Parent.ClickDetector.MouseClick:connect(onClick)

It works but it happens for one player. In Pairs loop delays the next one until the For loop which is inside it is finished.

I tried to make pairs to pairs but that also didn’t work.

Have your ipairs statement inside of your for d = statement.

function onClick (onClick)
	for d = 0,1,0.01 do
                for i,v in ipairs(game.Players:GetChildren()) do
	        local flash = v.PlayerGui.Blindness.Frame
		flash.BackgroundTransparency = d
		wait()
	end
	
end

end

script.Parent.ClickDetector.MouseClick:connect(onClick)
1 Like

Ok, this is epic. Thanks, my dude, really appreciate it.