I’ve been trying to make a Low Detail Mode that would make all textures transparent, set all of the part’s materials to SmoothPlastic, disable any effects and set the CastShadow property to false for each part when turned on and it would all revert back when turned off. However I’ve run into a problem where certain parts won’t revert back to normal and some effects turn on when they shouldn’t be.
I tried to put all the part’s, textures, and effect’s properties in a table whenever low detail detail mode was enabled. Then it would change back, using the table storing the properties, whenever it is disabled. However this solution didn’t work despite me not receiving any errors. If anyone could help out that would be great!
local PartTable = require(game.ReplicatedStorage.Modules.PartTable) --Stores all the interactable parts' properties (EX: size, color, and material)
local Player = game.Players.LocalPlayer
local Settings = Player:WaitForChild("SettingsFolder")
local LDM = Settings:WaitForChild("LowDetailMode")
local StoredProperties = {}
LDM.Changed:Connect(function()
if LDM.Value == true then
for _, Part in pairs(PartTable) do
for _, child in pairs(workspace:GetDescendants()) do
for _, effect in pairs(BasicEffects) do
if child:IsA("Part") then
if child.Material ~= Enum.Material.SmoothPlastic then
if not PartTable[child.Name] then
table.insert(StoredProperties, {[child.Name] = child.Material})
end
child.Material = Enum.Material.SmoothPlastic
child.CastShadow = false
end
elseif child:IsA("Texture") then
table.insert(StoredProperties, {[child.Name] = child.Material})
child.Transparency = 1
elseif child:IsA(effect) then
table.insert(StoredProperties, {[child.Name] = child.Material})
child.Enabled = false
end
end
end
end
game.Lighting.DepthOfField.Enabled = false
game.Lighting.Blur.Enabled = false
game.Workspace.Terrain.Clouds.Enabled = false
game.Workspace.Folder.ChildAdded:Connect(function(part)
if part:IsA("BasePart") then
part.Material = Enum.Material.SmoothPlastic
end
end)
print(StoredProperties)
print("Low Detail Mode Enabled!")
else
for _, Part in pairs(PartTable) do
for _, child in pairs(workspace:GetDescendants()) do
for _, effect in pairs(BasicEffects) do
if child:IsA("Part") then
if PartTable[child.Name] then
child.Material = PartTable[child.Name].Material
else
end
child.CastShadow = true
elseif child:IsA("Texture") then
child.Transparency = 0
elseif child:IsA(effect) then
child.Enabled = true
end
end
end
end
game.Lighting.DepthOfField.Enabled = true
game.Lighting.Blur.Enabled = true
game.Workspace.Terrain.Clouds.Enabled = true
print("Low Detail Mode Disabled!")
table.clear(StoredProperties)
end
end)
local PartTable = require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("PartTable")) --Stores all the interactable parts' properties (e.g. size, color, material)
local Player = game:GetService("Players").LocalPlayer
local Settings = Player:WaitForChild("SettingsFolder")
local LowDetailMode = Settings:WaitForChild("LowDetailMode")
local HighDetailProperties = {
["PartCastShadow"] = {},
["TextureTransparency"] = {},
["EffectEnabled"] = {}
}
local function StoreDefaultPropertiesForPart(Part)
local IsLowDetail = LDM.Value
if Part:IsA("Part") then
if HighDetailProperties["PartCastShadow"][Part] == nil then
HighDetailProperties["PartCastShadow"][Part] = Part.CastShadow
end
elseif Part:IsA("Texture") then
if HighDetailProperties["TextureTransparency"][Part] == nil then
HighDetailProperties["TextureTransparency"][Part] = Part.Transparency
end
else
if HighDetailProperties["EffectEnabled"][Part] == nil then
for _, Effect in ipairs(BasicEffects) do
if Part:IsA(Effect) then
HighDetailProperties["EffectEnabled"][Part] = Part.Enabled
break
end
end
end
end
end
local function ApplyDetailOptionForPart(Part)
local IsLowDetail = LDM.Value
if Part:IsA("Part") then
Part.CastShadow = IsLowDetail and false or HighDetailProperties["PartCastShadow"][Part]
elseif Part:IsA("Texture") then
Part.Transparency = IsLowDetail and 1 or HighDetailProperties["TextureTransparency"][Part]
else
for _, Effect in ipairs(BasicEffects) do
if Part:IsA(Effect) then
Part.Enabled = IsLowDetail and false or HighDetailProperties["EffectEnabled"][Part]
break
end
end
end
end
workspace.DescendantAdded:Connect(function(Child)
StoreDefaultPropertiesForPart(Child)
ApplyDetailOptionForPart(Child)
end)
local function ApplyDetailMode()
for _, Child in ipairs(workspace:GetDescendants()) do
StoreDefaultPropertiesForPart(Child)
ApplyDetailOptionForPart(Child)
end
end
LowDetailMode.Changed:Connect(ApplyDetailMode)
ApplyDetailMode()
(By the way, the error in your script is probably because you never disconnected the ChildAdded event.)
I referenced your code and tried to implement it into my own and I managed to get it to work!
Thank you so much for the help out, I really appreciate it!
Here’s the code for anyone who is curious
local PartTable = require(game.ReplicatedStorage.Modules.PartTable) --Stores all the interactable parts' properties (EX: size, color, and material)
local Player = game.Players.LocalPlayer
local Settings = Player:WaitForChild("SettingsFolder")
local LDM = Settings:WaitForChild("LowDetailMode")
local StoredProperties = {
["PartMaterial"] = {},
["PartCastShadow"] = {},
["TextureTransparency"] = {},
["EffectEnabled"] = {}
}
LDM.Changed:Connect(function()
if LDM.Value == true then
for _, Part in pairs(PartTable) do
for _, child in pairs(workspace:GetDescendants()) do
for _, effect in pairs(BasicEffects) do
if child:IsA("Part") then
if child.Material ~= Enum.Material.SmoothPlastic then
if not PartTable[child.Name] then
StoredProperties["PartMaterial"][child.Name] = child.Material
end
child.Material = Enum.Material.SmoothPlastic
child.CastShadow = false
end
elseif child:IsA("Texture") then
StoredProperties["TextureTransparency"][child.Name] = child.Transparency
child.Transparency = 1
elseif child:IsA(effect) then
StoredProperties["EffectEnabled"][child.Name] = child.Enabled
child.Enabled = false
end
end
end
end
game.Lighting.DepthOfField.Enabled = false
game.Lighting.Blur.Enabled = false
game.Workspace.Terrain.Clouds.Enabled = false
game.Workspace.Folder.ChildAdded:Connect(function(part)
if part:IsA("BasePart") then
part.Material = Enum.Material.SmoothPlastic
end
end)
print("Low Detail Mode Enabled!")
else
for _, Part in pairs(PartTable) do
for _, child in pairs(workspace:GetDescendants()) do
for _, effect in pairs(BasicEffects) do
if child:IsA("Part") then
if PartTable[child.Name] then
child.Material = PartTable[child.Name].Material
else
child.Material = StoredProperties.PartMaterial[child.Name]
end
child.CastShadow = StoredProperties.PartCastShadow[child.Name]
elseif child:IsA("Texture") then
child.Transparency = StoredProperties.TextureTransparency[child.Name]
elseif child:IsA(effect) then
child.Enabled = StoredProperties.EffectEnabled[child.Name]
--child.Enabled = true
end
end
end
end
game.Lighting.DepthOfField.Enabled = true
game.Lighting.Blur.Enabled = true
game.Workspace.Terrain.Clouds.Enabled = true
print("Low Detail Mode Disabled!")
print(StoredProperties.PartMaterial)
table.clear(StoredProperties.PartMaterial)
table.clear(StoredProperties.PartCastShadow)
table.clear(StoredProperties.TextureTransparency)
table.clear(StoredProperties.EffectEnabled)
end
end)