I am trying to make 2 settings, one to disable and enable sound and one to disable and enable Materials
Before disabling materials
After disabling materials
Before disabling sound
After disabling sound
Code to add the data (Server)
task.spawn(function()
local descendants = game:GetDescendants()
for i = 1, #descendants do
local obj = descendants[i]
if obj:IsA("BasePart") then
TablesModule.InsertMaterial(obj)
elseif obj:IsA("Sound") then
TablesModule.InsertVolume(obj)
end
end
TablesModule.PrintMaterialAmount()
end)
Code accessing the data (Local)
menu_settings_buttons.Materials.Button.Activated:Connect(function()
if MaterialsOn then
MaterialsOn = false
task.spawn(function()
effect_3_pos_off:Play()
effect_3_color_off:Play()
end)
task.spawn(function()
local descendants = workspace:GetDescendants()
for i = 1, #descendants do
local obj = descendants[i]
if obj:IsA("BasePart") then
obj.Material = Enum.Material.SmoothPlastic
end
end
end)
else
MaterialsOn = true
task.spawn(function()
effect_3_pos_on:Play()
effect_3_color_on:Play()
end)
if next(MaterialTable) then
print("MaterialTable is populated")
TablesModule.PrintMaterialAmount()
else
print("MaterialTable is empty")
TablesModule.PrintMaterialAmount()
end
task.spawn(function()
local descendants = workspace:GetDescendants()
for i = 1, #descendants do
local obj = descendants[i]
if obj:IsA("BasePart") then
local material = MaterialTable[obj]
if material then
obj.Material = material
end
end
end
end)
end
end)
menu_settings_buttons.Sound.Button.Activated:Connect(function()
if SoundOn then
SoundOn = false
task.spawn(function()
effect_4_pos_off:Play()
effect_4_color_off:Play()
end)
local descendants = workspace:GetDescendants()
VolumeTable = {}
for i = 1, #descendants do
local obj = descendants[i]
if obj:IsA("Sound") then
obj.Volume = 0
end
end
-- Check if VolumeTable is empty before playing sound
if next(VolumeTable) then
print("VolumeTable is populated")
TablesModule.PrintVolumeAmount()
else
print("VolumeTable is empty")
TablesModule.PrintVolumeAmount()
end
else
SoundOn = true
task.spawn(function()
effect_4_pos_on:Play()
effect_4_color_on:Play()
end)
local descendants = workspace:GetDescendants()
for i = 1, #descendants do
local obj = descendants[i]
if obj:IsA("Sound") then
local volume = VolumeTable[obj]
if volume then
obj.Volume = volume
end
end
end
end
end)
Code that contains all the data (Module)
local tables = {}
tables.MaterialTable = {}
tables.VolumeTable = {}
function tables.InsertMaterial(obj: BasePart)
tables.MaterialTable[obj] = obj.Material
end
function tables.InsertVolume(obj: Sound)
tables.VolumeTable[obj] = obj.Volume
end
function tables.PrintMaterialAmount()
local count = 0
for _, _ in pairs(tables.MaterialTable) do
count += 1
end
print("The amount of materials in the table are "..count)
end
function tables.PrintVolumeAmount()
local count = 0
for _, _ in pairs(tables.VolumeTable) do
count += 1
end
print("The amount of volume data in the table are "..count)
end
return tables
I have already put many prints to see what was the issue
I have looked on the developer form for solutions and haven’t found anything