I am adama88766, and I just started scripting Lua. I am super new to it. (Less than 3 weeks)
I have one of my first scripts that I have made, obviously using a tutorial, but I have a hunch it has to do with calling the part.
light = script.Parent.Parent.Parent.Parent.LightBox -- This is the light bulb
switch = script.Parent.Parent -- this is the switch
function onClick()
if light.PointLight.Range == 10 then
light.PointLight.Range = 0
else
light.PointLight.Range = 10 --how bright you want it to be
end
end
script.Parent.mouseClick:connect(onClick)
I want this script to work even if the lights are in a folder or a different destination.
Basically, I need knowledge on how to do the first 2 lines of this script. How to do the location of the light, and the switch.
So I can’t provide a screenshot, which would have been more helpful, but I can word it out.
So in the workspace, with a lot of other stuff, there is a folder called, “House”. In that folder there is another called “Garage”. In the folder “Garage”, there is another folder called “GarageLights”. And in that folder, “GarageLights” there is a model called “LightSwitch” With the script and light switch button, and all of the light switch parts, and there are 6 parts called “LightBoxes” with a pointlight and a frame for the actual light.
The script works if I put the model “LightSwitch” and all of the “LightBoxes” in the actual workspace put doesn’t work if I put it in a folder, or through multiple like above.
light = script.Parent.Parent.Parent.Parent.LightBox -- This is the light bulb
switch = script.Parent.Parent -- this is the switch
function onClick()
if light.PointLight.Enabled == false then
light.PointLight.Enabled = true
else
light.PointLight.Range = false
end
end
script.Parent.mouseClick:connect(onClick)
EDIT: The light script works, mine and yours, but the real problem is my previous reply. How to locate the light switch and the light boxes in folders.
I will just tell you what to do as this is simple.
Make a model and put two parts inside. One called “Switch” the other called “Light”.
Put a click detector and a script inside switch.
In the script type:
local light = script.Parent.Parent.Light.PointLight
local switch = script.Parent
switch.ClickDetector.MouseClick:Connect(function()
if light.Enabled == true then
light.Enabled = false
else
light.Enabled = true
end
end)
Then put a PointLight inside “Light” and done.
local folder = script.Parent.Folder --change "Folder" to whatever the folder's name is
local light = folder:WaitForChild("PointLight")
local switch = folder:WaitForChild("Switch")
light = script.Parent.Parent.Parent.Parent.LightBox -- This is the light bulb
switch = script.Parent.Parent -- this is the switch
function onClick()
if light.PointLight.Enabled == false then
light.PointLight.Enabled = true
else
light.PointLight.Enabled = false
end
end
script.Parent.mouseClick:connect(onClick)
They aren’t in a group, the model “LightSwitch” is a model with the light parts, the frame, screws, etc. and in that model there is a part called “switch” with a click detector and the script inside of the click detector. Then for the actual lights the switch is wired to, it is a part, not a model, with a pointlight and another part for a frame.
My actual question is, they work if they are in the workspace, but not if they are in the same folder, and that same folder is in 2 different folders.