I have this code that switches parts “on” and “off”. The parts are all children of the script, but script:GetChildren() isn’t working on them, and nothing is happening to the parts.
Hey oh yeah I am here is what your code should probably be like
uses a for loop to go through all your parts in table setting each one to that setting at almost the same time because of the spawnfunction
oh and i did update the code on the other post to format correctly now
local Parts = script:GetChildren() -- this gets a table of parts
while true do
for i , part in ipairs(Parts) do -- the for loop goes through the table of all your parts
spawn(function() -- need the spawn if you want it to do all parts at once else it will yield on each part
-- part here is the current part in the loop through the table
part.CanCollide = false
part.Material = Enum.Material.ForceField
wait(3)
part.Material = Enum.Material.Neon
part.Transparency = .3
wait(.5)
part.Material = Enum.Material.ForceField
part.Transparency = 0
wait(.5)
part.Material = Enum.Material.Neon
part.Transparency = .3
wait(.5)
part.CanCollide = true
part.Material = Enum.Material.Plastic
part.Transparency = 0
wait(3)
part.Material = Enum.Material.Neon
wait(.5)
part.Material = Enum.Material.Plastic
wait(.5)
part.Material = Enum.Material.Neon
wait(.5)
end)
end
end
and yeah your for loop would work i would suggest an ipairs with array table instead of using pairs pairs is mostly for dictionary
I fixed it, I just needed to add a wait timer at the end of the while loop
local Parts = script:GetChildren() -- this gets a table of parts
while true do
for i , part in ipairs(Parts) do -- the for loop goes through the table of all your parts
spawn(function() -- need the spawn if you want it to do all parts at once else it will yield on each part
-- part here is the current part in the loop through the table
part.CanCollide = false
part.Material = Enum.Material.ForceField
wait(3)
part.Material = Enum.Material.Neon
part.Transparency = .3
wait(.5)
part.Material = Enum.Material.ForceField
part.Transparency = 0
wait(.5)
part.Material = Enum.Material.Neon
part.Transparency = .3
wait(.5)
part.CanCollide = true
part.Material = Enum.Material.Plastic
part.Transparency = 0
wait(3)
part.Material = Enum.Material.Neon
wait(.5)
part.Material = Enum.Material.Plastic
wait(.5)
part.Material = Enum.Material.Neon
wait(.5)
end)
end
wait(9)
end
The wait statement is equivalent to all the wait statements in the for loop combined