How to slowly transparent all part in model

Here is the GIF:
https://gyazo.com/2551b363c255a7cc8efdbe001c8bfdba

Script:

local model = workspace.testgroup:GetChildren()

local trans = {}

wait(5)

for i,v in pairs(model) do
	if v:IsA("BasePart") then
		table.insert(trans,v)
	end
end

for i,v in pairs(trans) do
	for i = 0, 1, 0.25 do
		wait(0.05)
		v.Transparency = i
	end
end
6 Likes

Place the parts in a model, name it something appropriate

for index, instance in pairs(model:GetChildren()) do
   for i = 0, 10, 1 do
        instance.Transparency = i / 10
        wait()
   end
end
1 Like

My bad, I forgot to further explain,
‘for i = 0, 10, 1 do’
The 10 can be increased to a bigger number so the fading time takes longer, of course you would have to change the ‘i / 10’ to the same middle number.


https://gyazo.com/cacad8c6406ebc07da0d5afbbafc1e2c

Place the script in ServerScriptService

still same like in GIF on the top

I mean all part in one time, not one each.

You do realize that you can tween all the parts using tween service

Give me an example please. TheWiseAndGreat.

for i = 0, 10, 1 do
   for index, instance in pairs(model:GetChildren()) do
        instance.Transparency = i / 10
   end
   wait()
end

I mean like the all part will slowly transpareny together. Not one each.

Try that code I sent above please.

I already did, but it still same as mine.

Do a for i,v to make a fading in transarency is not a good use, for me. That hurts performance, consider using Tween Service TweenService | Documentation - Roblox Creator Hub

With TS, you can set the time of transition (I don’t know if that’s correctly written), ease direction and style (Bounce, Elastic, Linear, Etc.) And more!

In this case, you should follow this small example of where you should write the code:

for i,v in pairs(model) do
    if v:IsA("BasePart") then
	--Tween Code here.
    end
end

I hope this help! °w¬

2 Likes

This piece of code above, this will do all parts simultaneously.

Not sure if this would be a performace issue, but I’d make use of spawn() or coroutine to get the seamless transparency fade you’re looking for. This will run the fading function in a seperate thread without delaying looping through each part.

For example:

for i,v in pairs(model) do
	if v:IsA("BasePart") then
		   spawn(function()
               for i = 0, 1, 0.25 do
	     	   wait(0.05)
		       v.Transparency = i
            end)
	    end
	end
end

This way, you wouldn’t need to loop through the model twice and mess with tables or anything.

P.S. @AntivirusAVG, you can utilize TweenService as @TheWiseAndGreat mentioned above, if you’d like to read up on it, please check on the following article

3 Likes

Thanks for helping! this work well.

local Tween = game:GetService("TweenService")
local Info = TweenInfo.new(5) --how long it takes to fade
for __, P in pairs (testgroup:GetChildren()) do --make sure script is not in model
    T = Tween:Create(P,Info,{Transparency = 0})
    T:Play()
    wait() --if you want delays between each part or remove if you want all to diaper at once
end

Edit: forgot to play the tween fixed now

1 Like

This will make a much much smother fade and you can control how long it takes

1 Like

Not sure if this would solve the OP’s threading issue, but if it doesn’t make sure you wrap the contents of the loop in a coroutine or a spawn to multithread it.

I’m not sure if TweenService yields when you create and play a tween but this might be a better option on the performance end of things if it doesn’t.