Hello! The script below functions fine, but I'm trying to figure out how to run the numeric loop at the same time, for all of the "TV's"? It changes the transparency from 1 to 0 gradually, but I would like it to do it to multiple parts at once. Any tips? Thanks!
for _,v in pairs(game.Workspace["TV's"]:GetChildren()) do for i=1,0,-0.1 do wait(0.1) v.Screen.Decal.Transparency = i end end
It's pretty simple. Right now, you say 'for each TV, set the transparency to 1, 0.9, 0.8, ..., 0'.
What you mean to say is 'Set the transparency of each TV to 1, 0.9, 0.8, ...'
In other words, your loops are "inside out":
for i = 1, 0, -0.1 do wait(0.1) for _, v in pairs(game.Workspace["TV's"]:GetChildren()) do v.Screen.Decal.Transparency = i end end
EDIT: I missed moving the wait
-- you pause between changes in transparencies, not in switching between TVs
Roblox has a function named 'Spawn' that allows you to execute a code segment in a protected threat. It is one of the coroutine based functions that Roblox has built-in. It is basically just like running another script
Using spawn, we can make each part change transparency at the same time [or as close as possible]:
for _,v in pairs(workspace["TV's"]:GetChildren()) do spawn(function() for transparency = 1,0,-.1 do v.Transparency = transparency wait(.1) end end) end
Thus, this creates a new thread for each direct child under 'TVs' which will make sure the transparency is set!
http://wiki.roblox.com/index.php?title=Function_dump/Functions_specific_to_ROBLOX#Spawn
http://wiki.roblox.com/index.php?title=Loops#For
http://wiki.roblox.com/index.php?title=Function_dump/Coroutine_manipulation