I have a proximity prompt where I want all lights inside of a folder to turn off, but it keeps going to the wrong part in the model??? Someone help
local ProximityPrompt2 = script.Parent.ExternalBox.AttachmentPart.Attachment.ProximityPrompt
ProximityPrompt2.Triggered:Connect(function()
local LightFolder = game.Workspace.LightFolder
for i, v in pairs(LightFolder.Light:GetChildren()) do
if v.Name == "Part" then
print("WHY IS IT PICKING PART AND NOT LIGHTPART")
else
v.LightPart.PointLight.Enabled = false
end
end
end)
ProximityPrompt2.Triggered:Connect(function()
local LightFolder = game.Workspace.LightFolder
for i, v in pairs(LightFolder:GetDescendants()) do
if v.Name == "Part" then
print("WHY IS IT PICKING PART AND NOT LIGHTPART")
else
v.LightPart.PointLight.Enabled = false
end
end
end)
No errors or anything but it didnt toggle the lights some reason??
edit -
when adding an else to just run the same line again (shown below)
ProximityPrompt2.Triggered:Connect(function()
local LightFolder = game.Workspace.LightFolder
for i, v in pairs(LightFolder:GetDescendants()) do
if v:IsA("PointLight") then
v.Enabled = false
else
v.Enabled = false
end
end
end)
i get the error
Enabled is not a valid member of Model “Workspace.LightFolder.Light” - Server
local ProximityPrompt2 = script.Parent.ExternalBox.AttachmentPart.Attachment.ProximityPrompt
ProximityPrompt2.Triggered:Connect(function()
local LightFolder = game.Workspace.LightFolder
for i, v in pairs(LightFolder:GetDescendants()) do
if v:IsA("PointLight") then
v.Enabled = true
else
v.Enabled = false
end
end
end)
local ProximityPrompt2 = script.Parent.ExternalBox.AttachmentPart.Attachment.ProximityPrompt -- Grabs the ProximityPrompt so you can get the signal "Triggered".
ProximityPrompt2.Triggered:Connect(function() -- On the signal it calls the function
local LightFolder = game.Workspace.LightFolder -- Reference to the LightFolder
for _, v in pairs(LightFolder:GetDescendants()) do -- Begins iterating through the folder, not assigning anything to the index (as we do not use that in this code) and assign the instance to the variable of "v".
if v:IsA('PointLight') then -- Checks if our instance is a PointLight, this ensures we do not have any errors and we are only changing the correct class of instance.
v.Enabled = not v.Enabled -- Toggles it
end
end
end)
Edit: Added a comment to most lines explaining what they do.
Beat me to it;
The only flaw with this is that if you have one light that is enabled and another that is disabled, they wont all be synchronized. But as long as your model is consistent then it should be fine.