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
6 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:

01kit = script.Parent.Parent.Parent.Parent.Parent.Parent.StrobeLights
02 
03button = script.Parent
04 
05toggle = true
06 
07button.MouseButton1Down:connect(function()
08 
09 
10 
11if toggle == false then
12    toggle = true
13 
14    else
15while toggle == true do
View all 38 lines...

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:

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

1 answer

Log in to vote
2
Answered by 6 years ago
Edited 6 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