Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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!

2 comments

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]

0

In that case: Line 9: if workspace.Temp.Current.Value > 1200 then ChangeMaterial(workspace) end

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.

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.