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.
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?
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.