Here's the full script you're looking for.
1 | for i,part in ipairs (Workspace:GetChildren()) do |
2 | if part.Name = = "PutScriptHere" and part.ClassName = = "Part" then |
3 | script.ThingyScript:Clone().Parent = part |
For more info on this solution, visit http://wiki.roblox.com/index.php?title=Ipairs#ipairs
Below is alternate solution using a regular loop. They both do the same thing, but the previous script looks nicer and is easier to type out.
1 | parts = Workspace:GetChildren() |
3 | if parts [ i ] .Name = = "PutScriptHere" and parts [ i ] .ClassName = = "Part" then |
4 | script.ThingyScript:Clone().Parent = parts [ i ] |
(As a side note, pairs()
and ipairs()
do very similar things. pairs()
is used when you have tables with non-integer keys, while ipairs()
only supports integer keys. GetChildren()
always returns a table with integer keys only, so it's best to use ipairs()
in that situation.)