01 | function 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 |
(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).
First, I would recommend using a generic for
loop, ie, pairs
. That will reduce your use of list[i]
, which happens a lot.
01 | function 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 |
Now, I see there's a repeated chunk of code that fades out. We should probably make that into a function:
01 | function 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 |
08 | end |
09 |
10 | function 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 |
20 | 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.