Help with lights out script

I’m making a game where a monster spawns every few minutes, and im trying to make it so the lights go out when it does, but I’m having some trouble with the script. It’s not printing anything or turning off the point lights.

Script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local preacher = replicatedStorage:WaitForChild("Preacher")
local lightsOutSound = replicatedStorage:WaitForChild("Sounds"):WaitForChild("PowerOut")

local function toggleLights(enabled)
	for _, descendant in pairs(workspace:GetDescendants()) do
		if descendant:IsA("PointLight") then
			descendant.Enabled = enabled
		end
	end
	print(enabled and "Lights on" or "Lights out")
end

preacher.AncestryChanged:Connect(function(_, parent)
	if parent == workspace then
		local sound = lightsOutSound:Clone()
		sound.Parent = workspace
		sound:Play()
		toggleLights(false)
	else
		toggleLights(true)
	end
end)

Any help would be appreciated! :derp:

1 Like

Is the preacher being cloned? I don’t think this AncestryChanged would fire if it is. You’d need to connect to the event just after the clone was created.

In any case adding a print to the function connected to AncestryChanged would let you know if it’s firing at all and you could output what the new parent value is.

2 Likes

THANK YOU SO MUCH I FORGOT ABOUT THAT :sob:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.