Script for turning on all lights within a model doesn't work

I’m trying to make it so that all of the lights within parts called lightpart inside of this model turn on:
script.Parent.MouseButton1Click:Connect(function()
The script is:

game.Lighting.Brightness = 3
game.Lighting.ClockTime = 12
game.Workspace.lights.lightpart.SpotLight.Enabled = true
end)

and the workspace lights look like:
image

1 Like

You need to get all of the parts with the model.

for i, v in pairs(game.Workspace.lights:GetChildren()) do
    if v.Name == “lightpart” then
        v.Spotlight.Enabled = true
    end
end

This just gets all the children in the model with the name of lightpart. It then goes from there and turns on the lights for all of them

so.

game.Lighting.Brightness = 3
game.Lighting.ClockTime = 12
for i, v in pairs(game.Workspace.lights:GetChildren()) do
    if v.Name == lightpart then
        v.Spotlight.Enabled = true
end
end)

Just remove the parenthesis from the last end, and you’re good. Oh, and put quotations around lightpart. I had made that edit after you copied it

1 Like

Unfortunately, nothing happens, even though I copied the quotes.

its SpotLight with a captial L

1 Like

Even after I changed that, it still doesn’t work.

game.Lighting.Brightness = 3
game.Lighting.ClockTime = 12
for i, v in pairs(game.Workspace.lights:GetChildren()) do
    if v.Name == ''lightpart'' then
        v.SpotLight.Enabled = true
end
end

Oh, you can either use quotation marks or apostrophes (not sure if they are called this in coding)
if you use any, you only need to use it once, one at the start and one at the beginning.

game.Lighting.Brightness = 3
game.Lighting.ClockTime = 12
for i, v in pairs(game.Workspace.lights:GetChildren()) do
    if v.Name == 'lightpart' then
        v.SpotLight.Enabled = true
end
end

game.Lighting.Brightness = 3
game.Lighting.ClockTime = 12
for i, v in pairs(game.Workspace.lights:GetChildren()) do
    if v.Name == "lightpart" then
        v.SpotLight.Enabled = true
end
end
2 Likes