How would I change a property (Transparency, CanCollide, etc.) of every part that has the same name? When I try to do this, it only changes one of them.
You could put all the bricks in a model, and then use a for loop to change all of them.
Check this out:
modelOfBricks = game.Workspace.Model --The model with all the bricks in it. nameOfBricks = "ColorChange" --The name of the blocks that should be changed (keep quotations). for i,v in pairs(modelOfBricks:GetChildren()) do if v.Name == nameOfBricks then --Change properties here. I'll put one below as an example. v.Transparency = .5 --Changes every brick's transparency to .5 if they have the name. end end
If I helped, make sure to hit the Accept Answer button below my character! :D
No need to put all the parts in a model as Discern above stated.
function b(loc,name,wantedTrans,can) for _,v in pairs(loc:GetChildren()) do if v:IsA("BasePart") and v.Name == name then v.Transparency = wantedTrans v.CanCollide = can else b( v, name, wantedTrans, can ) end end end b(Workspace,"PartNameHere",.5,true)
Also, you can make a function to easily choose what properties you want to change directly in the parameters! Using tuples, this is easy!
function changeProps(loc,name,propArray) for _,v in pairs(loc:GetChildren()) do if v:IsA("BasePart") and v.Name == name then for prop,value in pairs(propArray) do v[prop] = value end else changeProps(v,name,propArray) end end end changeProps(workspace,'BasePlate',{Transparency=.5,CanCollide=.2,Name="STEVE"})