#change the transparency of all the parts-unions in a model

20 messages · Page 1 of 1 (latest)

rugged arch
#

im trying to have a model with hundreds of parts fade in and out of existence every now and then but I cant figure out how to select the whole model and everything inside of it with a script

#

i literally was putting a script in every part that controlled it

#

while true do script.Parent.Transparency = 0 script.Parent.Transparency = .1 wait(.1) script.Parent.Transparency = .2 wait(.1) script.Parent.Transparency = .3 wait(.1) script.Parent.Transparency = .4 wait(.1) script.Parent.Transparency = .5 wait(.1) script.Parent.Transparency = .6 wait(.1) script.Parent.Transparency = .7 wait(.1) script.Parent.Transparency = .8 wait(.1) script.Parent.Transparency = .9 wait(.1) script.Parent.Transparency = 1 wait(300) script.Parent.Transparency = .9 wait(.1) script.Parent.Transparency = .8 wait(.1) script.Parent.Transparency = .7 wait(.1) script.Parent.Transparency = .6 wait(.1) script.Parent.Transparency = .5 wait(.1) script.Parent.Transparency = .4 wait(.1) script.Parent.Transparency = .3 wait(.1) script.Parent.Transparency = .2 wait(.1) script.Parent.Transparency = .1 wait(.1) script.Parent.Transparency = 0 wait(10) end

#

literally an eyesore nightmare but im not a scripter at all

#

i cant figure out a way for this to apply to a whole model and not an individual part

#

change the transparency of all the parts-unions in a model

sleek marsh
#

you'd have to loop through all of the parts with a script

#

so something like this would go through all of the parts and set their transparency from 0 to 1 and then from 1 back to 0


for i, v in pairs(script.Parent:GetChildren()) do -- loop through whatever is in the folder/model your script is in
  if v:IsA("Part") or v:IsA("UnionOperation") then -- check that the item is a part or union
    for i = 1, 10 do
      v.Transparency = v.Transparency + 0.1
      task.wait(0.1)
    end

    for i = 1, 10 do
      v.Transparency = v.Transparency - 0.1
      task.wait(0.1)
    end
  end
end

gloomy haloBOT
#

studio** You are now Level 2! **studio

sleek marsh
#

but then thats gonna wait until one part is done before moving onto the next, so i would use coroutines to make it effect all parts at once

#

which would give you something that looks like this

for i, v in pairs(script.Parent:GetChildren()) do -- loop through whatever is in the folder/model your script is in
  if v:IsA("Part") or v:IsA("UnionOperation") then -- check that the item is a part or union
    coroutine.resume(coroutine.create(function()
      for i = 1, 10 do -- set the transparency from 0 to 1 over a 1 second duration
        v.Transparency = v.Transparency + 0.1
        task.wait(0.1)
      end

      for i = 1, 10 do -- set the transparency from 1 to 0 over a 1 second duration
        v.Transparency = v.Transparency - 0.1
        task.wait(0.1)
      end
    end))
  end
end

near charm
#

use tween service!

sleek marsh
#

yes thats another way

near charm
#

and way more readable, coroutines at this point should just be considered for performance sensitive things

sleek marsh
#

ahh alright

#

i will take that into account thank you

near charm
#

noo worries, have a nice day ^^