Improving my iteration of model:GetChildren()

Hello!

I started working on animating models when they are spawned into the Workspace. So far I have only managed to animate it by transitioning each part in the model from near-invisible to zero transparency.

Although, I do feel as though my method of iteration may not be the most efficient. Is there an alternative?

Video

Code

local BindableEvent = game.Workspace:WaitForChild("Event")

BindableEvent.Event:Connect(function(item) 

	local ServerStorage = game:GetService("ServerStorage")
	local modelClone = ServerStorage.Items:WaitForChild(item):Clone()
	modelClone.Parent = workspace
	
	for _, part in pairs(modelClone:GetChildren()) do
		while part.Transparency > 0 do
			wait(.05)
			part.Transparency = part.Transparency - 0.1
		end
	end
end)
1 Like

You could try using TweenService.

1 Like

Thank you! TweenService works great!

1 Like

Something to note is to use ipairs whenever iterating through arrays (or a numerical iterator if you can guarantee there are no holes in your table).