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

Problems with Transparency? Part 2

Asked by 10 years ago
function AdvancedLoad()
    local programs = game.Workspace:GetChildren()
    for a = 1,#programs do
        if programs[a].Name == "Program" or programs[a].Name == "SProgram1" or programs[a].Name == "SProgram2" then
           for i = 1, 0, -0.01 do
               wait()
               for k,v in pairs(programs[a]:GetChildren()) do
                   v.Transparency = i
               end
           end
           local modelparts = programs[a]:GetChildren() 
           for c = 1,#modelparts do 
               for d = 1, 0, -0.01 do 
                   wait() 
                   for k, v in pairs (modelparts[c]:GetChildren()) do 
                       v.Transparency = d
                   end
               end
           end
       end
   end
end

(Sorry, I'm not very good at scripting). Anyways, after some deep consideration (and help from others), I cut it down to this script. However, I've noticed that several problems have been occurring (such as the fact that the script keeps on repeating and blocks keep glitching out). Also, the programs with the models don't load or change transparency. I'm sorry to ask again, but could anyone help me with this issue? (Btw, I call this function later on in the script, so that isn't the problem).

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

First, I would recommend using a generic for loop, ie, pairs. That will reduce your use of list[i], which happens a lot.

function AdvancedLoad()
    local programs = game.Workspace:GetChildren()
    for _, program in pairs(programs) do
        if program.Name == "Program" or program.Name == "SProgram1" or program.Name == "SProgram2" then
            local modelparts = program:GetChildren() 
            for transparency = 1, 0, -0.01 do
                wait()
                for _, v in pairs(modelparts) do
                    v.Transparency = transparency
                end
            end
            for _, part in pairs(modelparts) do 
                for transparency = 1, 0, -0.01 do 
                    wait() 
                    for _, v in pairs(part:GetChildren()) do 
                        v.Transparency = transparency
                    end
                end
            end
        end
    end
end

Now, I see there's a repeated chunk of code that fades out. We should probably make that into a function:

function fade(model)
    for transparency = 1, 0, -0.01 do
        for _, part in pairs(model:GetChildren()) do
            part.Transparency = transparency;
        end
        wait();
    end
end

function AdvancedLoad()
    local programs = game.Workspace:GetChildren()
    for _, program in pairs(programs) do
        if program.Name == "Program" or program.Name == "SProgram1" or program.Name == "SProgram2" then
            fade(program);
            for _, part in pairs(modelparts) do 
                fade(part);
            end
        end
    end
end

Perhaps this makes what's going on clearer? I think it's odd/suspicious that you use fade on program and then again on each of its children... Is that the issue?

You didn't describe the problem very specifically, so I don't really know where to look.

0
The reason why I did that was because I wanted the parts in my models which were inside the program to fade out as well. However, I'm pretty sure the script kept running after I called the function, and the programs which had models inside them didn't even load at all. Here's some pictures: http://gyazo.com/b1bab779bffac2a78704c5281334968b http://gyazo.com/2567f8f94ad813621055ce3a3dd331ed http:/ poisonmonkey 30 — 10y
0
After some time, I managed to fix the glitch that prevented programs that with models inside of them to load. Although the script seems to be working, the parts are continually bugging out (like if you look at one at a certain angle, it disappears, and at another angle, it's there). poisonmonkey 30 — 10y
1
Nevermind, I understand my problem. It turns out that all of the bricks were at 0.01 at the end of the script. Okay, thanks for the help! poisonmonkey 30 — 10y
Ad

Answer this question