Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a script that makes every block in the game CORRODED? (the material)

Asked by 10 years ago

i wanted a script that could make every block corroded, for my core. here is what i TRIED:

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!

2 answers

Log in to vote
1
Answered by 10 years ago

This function is basically an expanded form of fireboltofdeath's answer:

function ChangeMaterial(Obj)
    for _,v in pairs(Obj:GetChildren()) do
        if v:IsA("BasePart") then
            v.Material = Enum.Material.CorrodedMetal
        end
        ChangeMaterial(v)
    end
end
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!

0
it helped a little bit, but, i wanted to make it happen once the core temperature (game.Workspace.Temp.Current.Value) gets to a surtain temperature. for example: if game.Workspace.Temp.Current.Value > 1200 then [your code] The_Sink 77 — 10y
0
In that case: Line 9: if workspace.Temp.Current.Value > 1200 then ChangeMaterial(workspace) end XanthicDragon 38 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
for i,v in pairs(workspace:GetChildren()) do
if v:IsA("Part") then
v.Material = "Corroded Metal"
elseif v:IsA("Model") then
for k,g in pairs(v:GetChildren()) do
if g:IsA("Part") then
g.Material = "Corroded Metal"
end
end
end
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.

0
Oh and remember: If a model is in a model it will not detect anything inside of that. I can add that. Just not for this one I added fireboltofdeath 635 — 10y

Answer this question