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! ![]()