Randomly iterate through parts of model, until entire model is transparent?
Asked by
8 years ago Edited 8 years ago
I'm trying to make a model fade with a "flicker-ish" effect by randomly iterating through each part of the model, then adding transparency, and repeating this process until ALL children of the model are transparent.
The script I have is kindof working. The problem I'm running into is that from time-to-time, not ALL of the parts in the model are made transparent, but the script ends anyways. So sometimes there will be 1, 2, 3, 4 or more parts that are still kinda visible although the function is finished. Why is this happening?
I've included the function below. If I can clarify anything further, please let me know.
Variables to know:
Fields
= a table of parts in the model
randHit
= a local table that I use to cross-check what parts have been fully modified or not (this step might be unnecessary, I use this check to eliminate further transparency checks since I know the part is already fully transparent)
hit
= a local bool that I set to true IF the part being checked is already inside of randHit
allTrans
= a bool that I use to fully check if ALL parts of the model are transparent. Is set to true each time the loop activates and then is set to false ANY time one of the parts isn't transparent enough. Loop only finishes if allTrans
is still true by the end
11 | local inc = math.random( 1 ,#Fields) |
12 | for i, v in pairs (randHit) do |
13 | if Fields [ inc ] = = v then |
19 | if Fields [ inc ] .Transparency > transAmt then |
20 | Fields [ inc ] .Transparency = Fields [ inc ] .Transparency - . 2 |
23 | table.insert(randHit,Fields [ inc ] ) |
30 | until numHit = = (#Fields) |
41 | until allTrans = = true |
44 | for _,v in pairs (script.Parent.buttons:GetChildren()) do |
45 | if v:IsA( "BasePart" ) then |
46 | v.BrickColor = BrickColor.new( "Lime green" ) |