Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script parents aren't being located. Can someone help?

Asked by
krez99 0
5 years ago

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?

0
What are all of those parents for? User#19524 175 — 5y
0
There parts in "StrobeLights" which have lights in them, so the script is made to toggle off/on the strobe effect krez99 0 — 5y
0
Have you heard of variables? https://www.lua.org/pil/1.html User#19524 175 — 5y
View all comments (2 more)
0
Why do you have lights in lights? Couldn't you move this script up seith14 206 — 5y
0
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? Danielp533 16 — 5y

1 answer

Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

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

Ad

Answer this question