So I have a map voting system I made up. The first voting session of the server works perfectly fine (no children in Lighting except StandardBloom, StandardColorCorrection, and Red). However, the following voting sessions successfully clear previous maps but the lighting doesn’t change, which is supposed to.
function VotingSession()
local function ClearCurrentMap()
for i, o in pairs(game.Lighting:GetChildren()) do --clears previous map's lighting
if not o.Name == "StandardBloom" or not o.Name == "StandardColorCorrection" or not o.Name == "Red" then
o:Destroy()
end
end
for i, o in pairs(workspace:GetChildren()) do --clears previous map's models
if o.Name == "Polar" or o.Name == "Islands" or o.Name == "Ocean" or o.Name == "Strait" then
o:Destroy()
end
end
end
local Voting = game.ReplicatedStorage.VotingSession
Voting.Value = true
local MapVotes = {}
wait(30)
Voting.Value = false
table.insert(MapVotes,mA.Value)
table.insert(MapVotes,mB.Value)
table.insert(MapVotes,mC.Value)
table.insert(MapVotes,mD.Value)
table.sort(MapVotes)
local Highest = MapVotes[#MapVotes]
if Highest == mA.Value then --clones map from storage and puts it in workspace, also parenting the appropriate lighting to game.Lighting
ClearCurrentMap()
local map = SS.Polar:Clone()
map.Parent = workspace
for i, o in pairs(map.Lighting:GetChildren()) do
o.Parent = game.Lighting
end
elseif Highest == mB.Value then
ClearCurrentMap()
local map = SS.Islands:Clone()
map.Parent = workspace
for i, o in pairs(map.Lighting:GetChildren()) do
o.Parent = game.Lighting
end
elseif Highest == mC.Value then
ClearCurrentMap()
local map = SS.Strait:Clone()
map.Parent = workspace
for i, o in pairs(map.Lighting:GetChildren()) do
o.Parent = game.Lighting
end
elseif Highest == mD.Value then
ClearCurrentMap()
local map = SS.Ocean:Clone()
map.Parent = workspace
for i, o in pairs(map.Lighting:GetChildren()) do
o.Parent = game.Lighting
end
end
mA.Value = 0
mB.Value = 0
mC.Value = 0
mD.Value = 0
end
How can I fix the lighting from previous maps not getting deleted as it should be in the local function ClearCurrentMap()?
Here is a screenshot of what happens when the previous map’s lighting doesn’t get cleared: