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

How do you make all parts do this at the same time?

Asked by 6 years ago

There's a lot of parts in this model and i want them all to do the transparency loops at the same time, but it seems to be only doing it 1 at a time?

for i,v in pairs(workspace.Model:GetDescendants()) do
        if v:IsA('BasePart') or v:IsA('Decal') then
            for i =1,10 do
            local num =0
            repeat wait()
                num = num + 1
            v.Transparency = v.Transparency + 0.1
            until num == 9
            local num =0
            repeat wait()
                num = num + 1
            v.Transparency = v.Transparency - 0.1
            until num == 9
            end
                v.Transparency = 1
        end
    end
end

0
Would it mess up your build to make the parts a single union? EnlightenedDev 11 — 6y
0
if v.ClassName == "Part" then greatneil80 2647 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago

(for i, v in pairs) -- this means that in pairs, it will transparent two at a time.

Use a different method like for list = 1, # do ..

local ModelContents = {workspace.Model:GetChildren()}

for MC = 1, #ModelContents do 
    if ModelContents[MC]:IsA('BasePart') or ModelContents[MC]:IsA('Decal') then 
        ModelContents[MC].Transparency = 0.5
        -- code 
    end
end
Ad
Log in to vote
0
Answered by 6 years ago
-- Example
part1 = script.Parent.p1
part2 = script.Parent.p2
part3 = script.Parent.p3
while true do
    for i = 1,10 do
        part1.Transparency = part1.Transparency + 0.1
        part2.Transparency = part2.Transparency + 0.1
        part3.Transparency = part3.Transparency + 0.1
        wait(1)
    end
    for i = 1,10 do
        part1.Transparency = part1.Transparency - 0.1
        part2.Transparency = part2.Transparency - 0.1
        part3.Transparency = part3.Transparency - 0.1
        wait(1)
    end
end
0
ya but the thing is theres like 100s of parts soo that would take forever ATestAccount420 31 — 6y
0
That would be the way to do that. You could also pass a list of parts to the loop. DeceptiveCaster 3761 — 6y
0
Roblox Lua isn't that easy, you know. DeceptiveCaster 3761 — 6y
Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Use a function called spawn() to run the code in a new thread.

for i,v in pairs(workspace.Model:GetDescendants()) do
    if v:IsA('BasePart') or v:IsA('Decal') then
        spawn(function()
            for i =1,10 do
                local num =0
                repeat wait()
                    num = num + 1
                    v.Transparency = v.Transparency + 0.1
                until num == 9
                local num =0
                repeat wait()
                    num = num + 1
                    v.Transparency = v.Transparency - 0.1
                until num == 9
            end
            v.Transparency = 1
        end)
    end
end

0
cool pls help me now dareveloper 9 — 6y

Answer this question