So, I tried making a toggle material gui for people that has low end PC, but it won't work and returns an error called
14:47:03.544 - Invalid value for enum Material
Is there a way to fix this? I'm assuming I did something bad with the Table {} but I still cannot figure out. Thanks in advance.
local players = game:GetService('Players')
local localplayer = players.LocalPlayer
local char = localplayer.Character or localplayer.CharacterAdded:wait()
repeat wait() until char:WaitForChild("Head")
local togglebutton = script.Parent
local materials = true
local smoothplastic = Enum.Material.SmoothPlastic
local objects = {}
wait(4)
local function scan(object)
for i,v in pairs(object:GetDescendants()) do
if v:IsA("Part") and v.Material then
table.insert(objects, v.Material)
end
end
end
scan(game.Workspace)
togglebutton.MouseButton1Click:Connect(function()
materials = not materials
if materials then
for i, v in pairs(game.Workspace:GetDescendants()) do
if v:IsA("Part") or v:IsA("UnionOperation") and v.Material then
v.Material=objects[i]
end
end
togglebutton.Text = 'UNTOGGLE LOW GFX MODE'
else
for i, v in pairs(game.Workspace:GetDescendants()) do
if v:IsA("Part") or v:IsA("UnionOperation") then
v.Material=Enum.Material.SmoothPlastic
end
end
togglebutton.Text = 'TOGGLE LOW GFX MODE'
end
end)
