Toggle Lights Not Working

I’m having problems with my light system working
Type: Script

Errors: nil

local LightsOnValue = game.ReplicatedStorage.LightsOn
local Lights = game.Workspace.Lights

--// Functions
function ToggleLights()
	for i,v in pairs(Lights:GetChildren()) do
		if v:IsA("Part") and v.Parent:FindFirstChild("PointLight") then
			v.Parent:FindFirstChild("PointLight").Enabled=game.ReplicatedStorage.LightsOn.Value
		end
	end
end

LightsOnValue.Changed:Connect(function()
	print("Light Value Changed")
	ToggleLights()
end)
Lights (Folder and instances)

image

LightsOn (Value)

image

--// Functions
function ToggleLights()
	for i,v in pairs(Lights:GetChildren()) do
		if v:IsA("Part") and v:FindFirstChild("PointLight") then
			v.PointLight.Enabled=game.ReplicatedStorage.LightsOn.Value
		end
	end
end

You were checking if v is a Part and if its Parent is a PointLight. You should’ve checked if PointLight is a child of the part (v).

1 Like

Ah, I should have seen that, thank you for your support! :white_check_mark: