Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

1 script for multiple bricks - ClickDetector for Spotlights. Why doesn't it work in my place?

Asked by 7 years ago

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!

0
That code looks fine, I'm not sure why it wouldn't work. Mayk728 855 — 7y
0
Do you get any errors in the output? Or did you not group the models correctly? Mayk728 855 — 7y
0
@iimayk I don't know what the issue is, It's just not working... KyleTheConqueror 5 — 7y
0
I feel like ROBLOX itself is the issue... KyleTheConqueror 5 — 7y
0
Bump KyleTheConqueror 5 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

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.

0
To respond to you, @JxkeBape, To disable them, I would have to put the script into another brick (off button perhaps), and change the Boolean to false. Your script should work, I'll return if not. KyleTheConqueror 5 — 7y
Ad

Answer this question