Hi,
I made a lightswitch that’s supposed to turn on/off all the wall lights in the main hall. I put all the models in one folder to call them, but sadly it doesn’t work.
Could someone explain to me what I’m doing wrong?

Hi,
I made a lightswitch that’s supposed to turn on/off all the wall lights in the main hall. I put all the models in one folder to call them, but sadly it doesn’t work.
Could someone explain to me what I’m doing wrong?
What you are doing is simply getting a single part, that well doesnt exist for that is not how you loop through parts and get the stuff in them.
What I’d recommend is looking into looping through objects, there are some tutorials out there that can teach you better than I can
It’s impossible to call parts.
What you can do is loop through the folder and set the light enabled property for each light.
local ProximityPrompt = script.Parent
local Bulb = game.Workspace:WaitForChild("Main Hall Lights"):WaitForChild("Bulb")
local Spotlight = Bulb.Spotlight
ProximityPrompt.Triggered:Connect(function()
for _, spotlight in ipairs(workspace["Main Hall Lights"]:GetDescendants()) do
if spotlight:IsA("SpotLight") then
spotlight.Enabled = not spotlight.Enabled
end
end
end)
This can help you manage better
So it’s the descendants you used? I’ll try and remember that. I tried your code, but sadly doesn’t work.
I managed to fix it
Updated code:
local ProximityPrompt = script.Parent
local LightsFolder = game.Workspace:WaitForChild("Main Hall Lights")
ProximityPrompt.Triggered:Connect(function(player)
for _, child in ipairs(LightsFolder:GetChildren()) do
local bulb = child:FindFirstChild("Bulb")
if bulb then
local spotlight = bulb:FindFirstChild("SpotLight")
if spotlight and spotlight:IsA("SpotLight") then
spotlight.Enabled = not spotlight.Enabled
end
end
end
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.