Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to loop through tables/instances?

Hello,

so i was trying to loop through a model to make all of it parts invsible but it seems to be a little delayed when the model has many parts and i can't lower the number of the parts so is there's any way i can loop trough that model faster

local Tween = game:GetService("TweenService")

local function MakeInvisible(Model)
	for _, Part in ipairs(Model:GetChildren()) do
		if Part:IsA("BasePart") then
			local Goal, Info = {Transparency = 1}
			,TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
			local Fade = Tween:Create(Part, Info, Goal)
			
			Fade:Play()
		end
	end
end

Thanks,

1 answer

✓ Accepted answer

You should reuse a lot of the variables since they are constants. There should not be a delay in the part fades as this code does not yield meaning that each tween will run after the code finishes.

Check that you are using the correct EasingDirection for your needs.

local Tween = game:GetService("TweenService")

local function MakeInvisible(Model)
	local Goal = {Transparency = 1}
	local Info = TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	
	local parts = Model:GetChildren()
	for i=1, #parts do
		if parts[i]:IsA("BasePart") then
			Tween:Create(parts[i], Info, Goal):Play()
		end
	end

end

hope this helps

This discussion is preserved as it was. New answers, comments, and votes are closed.