Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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!

5 comments

0

That code looks fine, I'm not sure why it wouldn't work.

0

Do you get any errors in the output? Or did you not group the models correctly?

0

@iimayk I don't know what the issue is, It's just not working...

0

I feel like ROBLOX itself is the issue...

0

Bump

1 answer

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.

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.