Cycling through a group/model to tween parts

Hello, what I’m trying to do is simply explained, I have a model that has 100 base parts in it and I want to tween them all to become invisible, but I’m not quite sure how I’d do that. If anybody knows how and could tell me, that’d mean a lot to me

Any and all help is greatly appreciated.

1 Like

Iterate the model parts with a loop, and tween or lerp its transparency value per part. I think it will be a bit resource-consuming thou

2 Likes

I see, could I not do anything along the lines of “Model:GetChildren” and go from there?

1 Like

To ‘cycle’ through the model and tween their transparency is a loop that goes part for part.

If you want to have one single step using the model:GetChildren() command you mentioned, you can do something like this;

local childrenOfModel = model:GetChildren()

childrenOfModel.Transparency = 1
2 Likes

If the parts in the model are all within the “same level” of the model, meaning all of them are direct children of the model yes. But if you have parts nested inside parts, then use Model:GetDescendants, to get absolutely all parts in the model, and use :IsA("BasePart") to check if that descendant is a part before trying to tween it

2 Likes

That wont tween them, just make it transparent instantly not over time. But yeah, if tweening or lerping is too much resource-consuming, would be preferably to not use the tween and make it instantly

2 Likes

oh this might just work give me just a second

1 Like

nevermind, as Peashie said, it would make them invisible, but not tween

1 Like

it’s just 1 model, 100 parts and 1 highlight

Correct, but it’s more to show just how to declare all the children in a variable and how to edit them after.

3 Likes

here’s the thing, I’m tinerking with a lightning module and I dislike how all the lightning gathers into one focal point, and I want to make the parts invisible before reaching that point

1 Like

Then I would go with :GetDescendants(), specially cause there are none more instances as decals, attachments, etc. And just iterate all its descendants choosing the baseparts by IsA:(“BasePart”) and if it is, proceed with the tween

2 Likes

So, something like this?

for i , parts in pairs(Group:GetChildren()) do
	if parts:IsA("BasePart") then
		Tween:Create(parts,TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out) , {Transparency = 1}):Play()
	end
end

???

I’m pretty new to scripting so this kind of stuff doesn’t make too much sense to me, sorry.

1 Like

Yeah, basically thats right, you could implement a table to create and save all tweens before playing them, and then a loop to Play() the table of the tweens previously created, only if you wish ofc.
Probably, make sure that you are not creating over and over all the tweens, handle the creation of tweens once, and have them ready to be used when its time.
You could reduce the creation of the multiple TweenInfos on each iteration of the loop too.

This is not complete code, but could give you an idea:

local tableOfTweens = {} 
local Info = TweenInfo.new(0.5,Enum.EasingStyle.Quad,Enum.EasingDirection.Out)

for i , parts in pairs(Model:GetDescendants()) do
	if parts:IsA("BasePart") then
		table.insert(tableOfTweens, Tween:Create(parts, Info , {Transparency = 1}))
	end
end
2 Likes

I’ll try this right now, thank you

2 Likes

And play them:

-- Play the tweens function
local function PlayTheTweens()
	for _, tween in pairs(tableOfTweens) do
		tween:Play()
	end
end

-- Play them
PlayTheTweens()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.