Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to loop through tables/instances?

Asked by
Is_Hunter 152
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

Ad

Answer this question