Script error table

hi, i suck at tables , could someone help me fix this ??
for i = 1,10,1 do
rods[i].Meterial = (“Metal”)
its saying Workspace.ControlRoom.Rods.Model.Script:21: attempt to index field ‘?’ (a nil value)

Maybe this?

Did you mean Material?

i contacted a scripter , this is resolved, my table was wrong and this also

If you wanted to iterate through a table of objects and change the material of each part you would try something like this.

for i,v in pairs(parts:GetChildren()) do
    v.Material = Enum.Material.Metal
--untested code

GetChildren() would get individual part objects in a model, or folder, and put it in a table.

Hopefully this provides an understanding.

Use ipairs when working with GetChildren. pairs is for iterating through dictionaries which GetChildren does not return.

1 Like

Odd, because I’ve used it throughout my whole scripting career and it works perfectly every time.

Yes it works but pairs is idiomatically improper for arrays. pairs iterates over a table in an arbitrary order because the keys are indeterminate, while ipairs is meant to iterate over contiguous arrays at an i++ key basis.

pairs and ipairs helps make it clear what you’re iterating over for both yourself and collaborators and in some cases has been the determining factor between something working as intended or not. You can search for such examples around the forum.

There are many posts you can look up to understand the difference between these. Particularly, I’ve spoken about them quite a bit and AMD_chan has a few posts of his own on it, among others.