How to change the transparency of multiple parts at once with for loop

So if I used a for loop then the first part would need to finish first which would delay the other parts so how would I change all parts transparency at once

Here is a basic script that does this:

local Location = workspace -- where the parts are located

for i, v in pairs(Location:GetChildren()) do -- gets instances inside location
	if v:IsA("BasePart") then -- is it a part/union/meshpart etc.
		v.Transparency = 1 -- transparency
	end
end
2 Likes

i want it fade out by using for loop but that would do one by one

To achieve the fading effect, one way you could do this is by using TweenService. The modified code would look like this:

local TweenService = game:GetService("TweenService") 
local Location = workspace -- where the parts are located

local Transparency = 1 -- target transparency
local FadeTime = 1 -- in seconds, how long it takes to fade

local tweenInfo = TweenInfo.new(FadeTime)

for i, v in pairs(Location:GetChildren()) do
	if v:IsA("BasePart") then
		local Tween = TweenService:Create(v, tweenInfo, {Transparency = Transparency})
		Tween:Play()
	end
end
1 Like

His original post asked the following:

how would I change all parts transparency at once

If the tween starts does the code go to another part straight away or does it wait until it finishes

The code provided should tween all of the parts straight away without delay.

How do I change the amount of transparency per second

Edit variable FadeTime to a number above 1.

1 Like

If I want to make it faster I lower the fade time and slower I increase

1 Like

I like ur code with tweening but is there a way to make it a for loop at once all parts

The tween is being performed for all parts at once, tweens do not yield the current thread of execution unless you explicitly instruct them to do so.

If you want to increase the tween’s speed then simply reduce the tween’s time duration.

The loop should be too fast for it to even render that the parts have been changes one by one.