So I am having an issue with my script, and I have done all I could to solve it. What I want to do is create a function that turns on multiple lights with a simple on and off switch.
script.Parent.ClickDetector.MouseClick:connect(function() for _,Part in pairs(workspace.Lights.CL:GetChildren()) do if Part:FindFirstChild("SpotLight") then Part.SpotLight.Enabled = true end end end)
So this is what I've done to troubleshoot with no success:
-- I've tried to change the names of the models I used them for.
-- I've deleted the Part/Model and recreated it.
What is interesting, however:
-- It works in studio mode > Play here with other places/games.
-- It works if I paste the code and write in the name for each Part/Model (which is a waste of time).
Any help? I'm still learning to code, so any help I can get would be useful. thank you!
This should work to enable the lights with 1 button:
local lights = game.workspace.Lights function onClick() for i, v in pairs(lights:GetChildren()) do v.SpotLight.Enabled = true end end script.Parent.MouseClick:connect(onClick)
I am not sure how to disable the lights but that will work to enable them.