i wanted a script that could make every block corroded, for my core. here is what i TRIED:
1 | game.Workspace.GetChildren.Material( "Corroded Metal" ) |
but GetChildren
and Material
were both not accepted. They are not correct commands. if you have the correct commands, or a whole new script, that would be great! thanks!
This function is basically an expanded form of fireboltofdeath's answer:
1 | function ChangeMaterial(Obj) |
2 | for _,v in pairs (Obj:GetChildren()) do |
3 | if v:IsA( "BasePart" ) then |
4 | v.Material = Enum.Material.CorrodedMetal |
5 | end |
6 | ChangeMaterial(v) |
7 | end |
8 | end |
9 | ChangeMaterial(game.Workspace) |
This function will iterate through all the children of the workspace, the through the children's children, and so forth. It will get every single brick in the workspace and change its Material
to CorrodedMetal
. Hope this helped!
01 | for i,v in pairs (workspace:GetChildren()) do |
02 | if v:IsA( "Part" ) then |
03 | v.Material = "Corroded Metal" |
04 | elseif v:IsA( "Model" ) then |
05 | for k,g in pairs (v:GetChildren()) do |
06 | if g:IsA( "Part" ) then |
07 | g.Material = "Corroded Metal" |
08 | end |
09 | end |
10 | end |
11 | end |
This uses GetChildren to detect if it is a part or a model. If it is a model it'll look inside for more parts.