I want to make it so when a Player presses a button on their screen, the script will go and change parts with a specific material to plastic. I’ve attempted this with many different arranges to the code, but the only thing I got closest to was making it change every part in the game to Plastic regardless of it having a specific material or not, which isn’t what I’m looking for.
I’ve looked around the Developer Forum and no one asked and got this question answered specifically. My game has a Mobile player base, and a PC player base, and is prone to lag issues. I’ve reduced the much graphical things I can, but it hasn’t done much for me.
I’m not asking for a huge script, I just want to know if this can be done, and if so, how can I fix this code so that it does exactly what I’m looking for? The script below is the most recent I’ve typed, and it does nothing.
If you need anymore information, please let me know!
local FlaggedMaterials = {Enum.Material.Glass, Enum.Material.Metal, Enum.Material.Ice, Enum.Material.Neon, Enum.Material.DiamondPlate}
local PartsToChange = workspace:GetDescendants()
script.Parent.MouseButton1Click:Connect(function()
for i, PartFlagged, BannedMaterial in pairs(PartsToChange, FlaggedMaterials) do
wait()
if PartFlagged:IsA("BasePart") then
if PartFlagged.Material == BannedMaterial then
PartFlagged.Material = Enum.Material.SmoothPlastic
print("Material Changed.")
end
end
end
end)
local FlaggedMaterials = {Enum.Material.Glass, Enum.Material.Metal, Enum.Material.Ice, Enum.Material.Neon, Enum.Material.DiamondPlate}
local PartsToChange = workspace:GetDescendants()
script.Parent.MouseButton1Click:Connect(function()
for i, Part in pairs(PartsToChange) do
wait()
if Part:IsA("BasePart") or Part:IsA("Part") then
if table.find(FlaggedMaterials, Part.Material) then
Part.Material = Enum.Material.SmoothPlastic
print("Material Changed.")
end
end
end
end)
I think this should work. Let me know if there are any issues.
Well, by the looks of it, nothing appears to happen at all. It’s supposed to print if the material changed to confirm that it actually did, but I’m not seeing any of that in the Dev Console, or studio Console. Not even printing an error which is really strange. It might be an issue with the if statement, just not sure what
My script is located as a child of a GUI button. Since I’m getting the descendants of the workspace, it shouldn’t matter where I put the script. Since it’s using MouseButton1Click it’s a button, and it’s located right under just that. Here’s a tree if it helps:
Nvm just realized I had it disabled. I’m so dumb . I’ll see if it works
Thank you so much, this worked just fine. I will learn from this information in the future, sorry for my uh lack of fact checking. I marked your post as solution.