Lighting children not getting deleted?

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:
Screen Shot 2020-10-22 at 11.33.33 AM

1 Like

change to

if o.Name ~= "StandardBloom" and o.Name ~= "StandardColorCorrection" and o.Name ~= "Red" then
1 Like

That actually ends up deleting everything in lighting (including StandardBloom, StandardColorCorrection, and Red) and putting the next map’s lighting in.

EDIT:
I could actually just put StandardBloom, StandardColorCorrection, and Red in each of the map’s lighting folders, but I’ll have to test it first.

did you test it, since I am almost certain that, this won’t delete it.

local o = Instance.new("Part")
o.Name = "StandardBloom"

if o.Name ~= "StandardBloom" and o.Name ~= "StandardColorCorrection" and o.Name ~= "Red" then
	print(1)
	o:Destroy()
else
	print(2)
end

edit: it won’t delete it, I just tested it in studio.

It did delete everything, but I found a different solution.