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