I am trying to make a setting which makes everything “SmoothPlastic” and when you disable the setting, it turns back to the original materail.
![image](//devforum-uploads.s3.dualstack.us-east-2.amazonaws.com/uploads/original/4X/b/a/d/bad2d62480f1ae004a2708b3ea0158746ae9f675.png)
i am currently using an invoker (which is probably the worst desicion i have made)
especially since using an invoker is really slow and ping-based
is there another way of changing the materials back?
for i,v in pairs(workspace:GetDescendants()) do
if v and v:IsA("BasePart") then
local Mat = script.Invoke:InvokeServer(v) --// Change this?????
v.Material = Mat
end
end
Wehn changing the material to smooth plastic, store the material of the part in a dictionary before changing the material, then just go through the dictionary and set the part’s material back to the original one
Quick example
local materials = {}
for _, part in ipairs(workspace:GetDescendants()) do
if not part:IsA("BasePart") the
continue
end
materials[part] = part.Material
part.Material = Enum.Material.SmoothPlastic
end
--To change back
for part, material in pairs(materials) do
part.Material = material
end
idk if that would cause any issues, especially since the game that i am making contains a lot of cloned and deleted parts (minigames)
especially since this is dealt on a localscript
If performance of going through all the descendants of workspace is an issue, then you can put all the things that definitely will be seen by the player in a folder and go through that folder. But if they’re not a descendant of workspace, then it’s okay.
But what you could do as well is make it so when the client first joins, the localscript goes through all the descendants of workspace, and puts all the parts in the dictionary with the key being the part, and the value being their original material.
Then when you want to change their material to SmoothPlastic, just do what I did for looping through the dictionary, but make the material be SmoothPlastic instead of material
1 Like