Hello I've got a problem with locating a certain model
I've got a button which toggles off/on strobe lights for a plane. I've got a GUI in a first officers seat, when you sit in the seat you get the gui, the button is in the GUI.
The button contains this code:
kit = script.Parent.Parent.Parent.Parent.Parent.Parent.StrobeLights
button = script.Parent
toggle = true
button.MouseButton1Down:connect(function()
if toggle == false then
toggle = true
else
while toggle == true do
wait(0.01)
kit.LightA.PointLight.Enabled = true
kit.LightA.BillboardGui.Enabled = true
wait(.05)
kit.LightA.PointLight.Enabled = false
kit.LightA.BillboardGui.Enabled = false
wait(0.05)
kit.LightA.PointLight.Enabled = true
kit.LightA.BillboardGui.Enabled = true
wait(0.05)
kit.LightA.PointLight.Enabled = false
kit.LightA.BillboardGui.Enabled = false
wait(1)
end
end
end)
button.MouseButton2Down:connect(function()
toggle = false
end)
The problem is, the script locates it's Parents before it's equipped and it locatesthem after. Even though other codes uses the exact same line:
kit = script.Parent.Parent.Parent.Parent.Parent.Parent.StrobeLights
Is there a way to make it locate only before it's equipped?

6 comments
What are all of those parents for?
There parts in "StrobeLights" which have lights in them, so the script is made to toggle off/on the strobe effect
https://gyazo.com/437cfc1f6d7639d8e1f53b8c627542de
Have you heard of variables? https://www.lua.org/pil/1.html
Why do you have lights in lights? Couldn't you move this script up
yes roblox might misinterpret code bc you have all those "Parents". Define the direcoty using something like:game.Workspace.Part and not script.Parent.Parent forever and ever. Also do you know what varibles are?