Light script not working

i have been trying to make a script that enables the light in all parts because i want to make a system where when we click a button all the lights turn on (basically a power box), but when i tried it it didnt work, the problem isn’t from the script, as i added a “print” function to check if it worked, well, it just printed every single thing in the workspace…

The script
script.Parent.ClickDetector.MouseClick:Connect(function()
	for i,v in pairs(workspace:GetDescendants()) do
		if v:IsA("BasePart") and v:FindFirstChildOfClass("PointLight") and v.Name == not "OHMAHGAWD" and v.Name == not "DWAGHAMHO" then
			v:FindFirstChildOfClass("PointLight").Enabled = true
			print(i..[[ = ]]..v)
		else
			print(v, [[isn't a light...]])
		end
	end
end)

Yes, i will remove the print(v, [[isn't a light...]]) from the script as it freezes the game, i just added it for testing purposes.

Thanks in advance for the help.

You could try simply checking if v:IsA("PointLight"), then you could do v.Enabled = true, maybe that’ll fix the issue.

1 Like

Thank you so much for your help!

First use GetChildren() instead of GetDescendants(), u dont need to check through whole Workspace, if you use a Folder u can use for i,v in pairs(workspace.Folder:GetChildren()) do if not then just for i,v in pairs(workspace:GetDescendants()) do and can u send me the Location for the PointLight and all of the Parents and names?

They were all in workspace but not really all in the same folder/model, thats why i used workspace:GetDescendants()

Another thing you can do is using Roblox’s Tag Editor and CollectionService.
Basically you go to Plugins > Tag Editor Window, create a new tag and name it “Lights” for example.
After that you select all PointLights and tick the box next to the tag you’ve created to add all these selected parts to it.

Next you make a script that uses CollectionService like this:

for _, light in pairs(game:GetService("CollectionService"):GetTagged()) do
    v.Enabled = true
end

That’ll get all the tagged objects - the PointLights in that case - and enable all of them without having to worry about anything else inside Workspace.

1 Like

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