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
01function AdvancedLoad()
02    local programs = game.Workspace:GetChildren()
03    for a = 1,#programs do
04        if programs[a].Name == "Program" or programs[a].Name == "SProgram1" or programs[a].Name == "SProgram2" then
05           for i = 1, 0, -0.01 do
06               wait()
07               for k,v in pairs(programs[a]:GetChildren()) do
08                   v.Transparency = i
09               end
10           end
11           local modelparts = programs[a]:GetChildren()
12           for c = 1,#modelparts do
13               for d = 1, 0, -0.01 do
14                   wait()
15                   for k, v in pairs (modelparts[c]:GetChildren()) do
View all 22 lines...

(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.

01function AdvancedLoad()
02    local programs = game.Workspace:GetChildren()
03    for _, program in pairs(programs) do
04        if program.Name == "Program" or program.Name == "SProgram1" or program.Name == "SProgram2" then
05            local modelparts = program:GetChildren()
06            for transparency = 1, 0, -0.01 do
07                wait()
08                for _, v in pairs(modelparts) do
09                    v.Transparency = transparency
10                end
11            end
12            for _, part in pairs(modelparts) do
13                for transparency = 1, 0, -0.01 do
14                    wait()
15                    for _, v in pairs(part:GetChildren()) do
View all 22 lines...

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

01function fade(model)
02    for transparency = 1, 0, -0.01 do
03        for _, part in pairs(model:GetChildren()) do
04            part.Transparency = transparency;
05        end
06        wait();
07    end
08end
09 
10function AdvancedLoad()
11    local programs = game.Workspace:GetChildren()
12    for _, program in pairs(programs) do
13        if program.Name == "Program" or program.Name == "SProgram1" or program.Name == "SProgram2" then
14            fade(program);
15            for _, part in pairs(modelparts) do
16                fade(part);
17            end
18        end
19    end
20end

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