Light switch not working

If you dont know what the tree is,its basically the explorer

1 Like

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)

House(Folder)
VVVVV
Garage(Folder)
VVVVVV
GarageLights(Folder)
VVVVVV
LightSwitch(Model)
VVVV
Script,LightBoxes(6), (Parts)

LightBulb = script.Parent(LightSwitch).Parent(GarageLights).Parent(Garage).Parent(House)
Switch = script.Parent(LightSwitch).Parent(LightBoxes)

1-Alright,one of the things i noticed is that there are “6” parts in the light switch,but he doesnt reference the correct one.

2-The first variable is reverse?

There are probably others errors,but i will type the code you should type:

LightBulb = ???--Change LightBox,to the name of the part you must click to turn the light off
Switch = script.Parent?????????

alright,this is very badly organized,i cannot help you this way,maybe when you organize is correctly,i can explain you.

Folder don’t really work for me so i use groups instead try using groups instead of folder.
capture123
Kinda look like this

Sorry was afk for some time,

I will provide a screenshot of my tree

Screenshot (2) cut

Try grouping all of the “LightBoxes”

So switch is the “Button” that ticks?/The button that when clicked,makes the light off

Models are better for Parts/Objects

Folders are better to organize things,like scripts.

The script is in the ClickDetector?Dude,ok,ok,move it to the “switch”/like it is an brother of the ClickDetector

Can you click at the PointLight and show its properties?(Take a ScreenShot)

Judging from that, i would insert a script into the switch (if it already has a click detector)

local switch = script.Parent
local light = script.Parent.Parent.LightBox

switch.ClickDetector.MouseClick:Connect(function()
       if light.PointLight.Enabled == true then
         light.PointLight.Enabled = false
      else
         light.PointLight.Enabled = true
end)

In a folder? I like folders but if models work, then sure,

Screenshot (3) cut

IndustrialLight is the light frame, misnamed that.

EDIT: Currently checking if @Suuzv script works.
EDIT 2: Nope, not seeming to work…

Keep checking my answers in there!!!

hmmm
Let me just redo what i said.

You want to make a light switch where if you clicked it then light would turn on.

So
capture123
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)

1: “switch” is the button that ticks on and off.
2 and 3: Okay, didn’t know, will use.
4: Will do
5: Will provide another screenie

So, first you say workspace, then the after the next (dot) you do the biggest parent, then so on till its closest parent?

What i am telling is first understand how it works then change around the variable
And what you say is pretty close

Screenshot (4) cut

Okay changing the script.

30char

Wait so, is the workspace supposed to be first or last?
This:

local switch = script.switch.LightSwitch.GarageLights.Garage.House.workspace

Or this:

local switch = workspace.House.Garage.GarageLights.LightSwitch.switch.script

it can be any way around because the variables does not interfere with each other

1 Like