Why are none of the parts being affected by this script?

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.

local Parts = script:GetChildren()
while true do
	
	Parts.CanCollide = false
	Parts.Material = Enum.Material.ForceField
	wait(3)
	Parts.Material = Enum.Material.Neon
	Parts.Transparency = .3
	wait(.5)
	Parts.Material = Enum.Material.ForceField
	Parts.Transparency = 0
	wait(.5)
	Parts.Material = Enum.Material.Neon
	Parts.Transparency = .3
	wait(.5)
	Parts.CanCollide = true
	Parts.Material = Enum.Material.Plastic
	Parts.Transparency = 0
	wait(3)
	Parts.Material = Enum.Material.Neon
	
	wait(.5)
	Parts.Material = Enum.Material.Plastic
	
	wait(.5)
	Parts.Material = Enum.Material.Neon
	
	wait(.5)
end

you are referencing to the table here not a part you need a for loop to go through the parts

Hey, you’re the same guy from my last post earlier today! Also, thank you, I’ll look at that

1 Like
for _, part in pairs(Parts) do
		part.CanCollide = false
		part.Material = Enum.Material.ForceField
	end

Would something like this work?
Sorry if this sucks, I’m not good with for loops.

1 Like

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

Nothing happens when I run this

Nevermind, things are running, just at a very very very fast speed.

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

2 Likes

oh yeah you may want to remove the .5 from the end of that for loop its not really needed

remove the spawn(function() and the end)