Material Toggle Help

Ello, quick introduction. Anyways I’m making a settings UI that multiple people will be able to use in their games. I’ve nailed everything except one thing, how do I make a toggle to set all materials in game to smooth plastic? Not sure if I can ask for this sort of help, here’s the base to my code,

materials.Toggle.MouseButton1Click:Connect(function()

end)

I have an idea! You could loop through the stuff in workspace and set the material to smooth plastic

materials.Toggle.MouseButton1Click:Connect(function()
stuff=game.Workspace:GetChildren()
for i, v in pairs(stuff)
v.Material="SmoothPlastic"
end)

or you could put all the stuff you wanted the material changed into something in the workspace and loop through that

okay! ill try it and let you know how it works out.

Didn’t work, and cannot do the second option because its going to be a product and everyone’s workspace’s are different.

try this

for i,v in pairs(game.workspace:GetDescendants())do
	if v:IsA("Part") or v:IsA("MeshPart") then
		v.Material = Enum.Material.SmoothPlastic
	else
		
	end

end
1 Like

I have a question. What is the class of the things in the workspace you are trying to change the materials of? You could adjust the code I posted earlier
I did not test the code I posted earlier, as it was just a way to show what I meant when I said “You could loop through the stuff in workspace and set the material to smooth plastic” and I apologize :frowning:

Yours Wouldn’t work on everything.

Trying to toggle the all the parts in the workspace’s materials to smooth plastic in an attempt to reduce lag and gain FPS.

Sadly also did not work. Though it took up no errors unlike Fiercest’s code.

Mines Would get every thing in the Workspace

Alright! You should use MazenEz’s code then!

Ayyy it worked!! Thanks so much. Forgot to add the else part lol.

Now I need to figure how to change it back…

Could you mark it as solution? So Other people when they need help they can see the Solution

1 Like

Done, but I still need some help with changing it back.

Wait I will when this topic is officially over.

You didn’t ask to set it back.
You Asked how could you make it

great job MazenEz! I had no idea the getDescendants function existed before you said it here!

Thanks! Good Job to!
We Learn every day something new

Oh mb I forgot too. Sorry about that.