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?
Hello
If you want to accurately locate a model you should do:
game:GetService('Workspace')['MODELNAMEHERE']
You can also use:
script:FindFirstAncestor('MODELNAMEHERE')
If your script is located under a lot of models/parts/folders etc. you should not use script.Parent.Parent.Parent…... because
a) This will create a lot of mess in your code.
b) You are not sure if the parent you are locating is actually the model you want to locate.
~Frag