|
| 24 Mar 2014 09:45 PM |
| Hello and im trying to make a script. and the script hase a parent, but the scripts parent also has a parent. In the script how do i refer to the script's parent only without using Parent.Parent??? |
|
|
| Report Abuse |
|
|
tery215
|
  |
| Joined: 19 Aug 2009 |
| Total Posts: 3879 |
|
| |
|
|
| 24 Mar 2014 09:50 PM |
this is what i have but it also moves the parent of the script?
function GUIClick() if (Switch == "Open") then script.Parent.Parent.Position = UDim2.new(0.-4, 0, 0, 0) script.Parent.Text = "<--" Switch = "Close" elseif (Switch == "Close") then script.Parent.Parent.Position = UDim2.new(0, -4, 0, 0) script.Parent.Text = "-->" Switch = "Open" end end |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2014 09:50 PM |
scriptParent = game.Workspace:FindFirstChild(script.Parent.Name,true)
FindFirstChild() now has two arguments, finding the name, and going through all the children of workspace and going into their children etc. until it finds the name. Only downside is, make sure that the name of the scriptParent is different from everything else. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 24 Mar 2014 09:51 PM |
| FindFirstChild always had 2 arguments |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2014 09:51 PM |
| oh. Totally different scenario. Ignore my last post. |
|
|
| Report Abuse |
|
|
|
| 24 Mar 2014 09:54 PM |
blargh I can't say one thing without someone else posting something new!
Well, I didn't know that :FindFirstChild() not only searched for a name, but also scans the children of it and its children's children etc.
I've been using a function that goes through everything.
function unpack(model) for i,v in pairs(model:GetChildren()) do if v:IsA("Part") then v.CanCollide = false elseif v:IsA("Model") then unpack(v) end end end
unpack(workspace)
I KNOW that this skips over scanning parts and terrain and wedges and the camera, but its a short rendition to the original function. |
|
|
| Report Abuse |
|
|