is your family tree that is in the folder like this?
GarageFolder(the main folder)
Script
LightsFolder
Light
PointLight
LightSwitch
ClickDetector
if so then i see nothing wrong with the tree.
as along as the main folder(GarageFolder) is parented to the workspace, then you need to change your script.
i recommend this if the tree is like the one ive shown above:
light = script.Parent.LightsFolder.Light -- This is the light bulb
switch = script.Parent.LightSwitch -- this is the switch
function onClick()
if light.PointLight.Enabled == false then
light.PointLight.Enabled = true
else
light.PointLight.Enabled = false
end
end
switch.ClickDetector.mouseClick:connect(onClick)
You want to make a light switch where if you clicked it then light would turn on.
So
I would first put stuff like that.
Then the script inside Switch should be
local light = script.Parent.Parent.Light.PointLight -- making a variable for light
local switch = script.Parent -- making a variable for switch
switch.ClickDetector.MouseClick:Connect(function() -- when the switch is clicked then run this function
if light.Enabled == true then -- if the light is on then
light.Enabled = false == turn it off
else -- if it is off then
light.Enabled = true -- turn it on
end
end)
Run this and it should work.
If you want to do it the way you did inside your tree then.
Change the variable which is
local light = script.Parent.Parent.Light.PointLight
local switch = script.Parent
Set the light’s variable to where the light might be located.
Maybe like
local light = workspace.House.Garage.GarageLights.LightBox
No need to change the switch’s variable if the script is inside the switch (not the click detector)