Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 16 Jun 2016 02:25 PM |
function findParent(mdl) print('>>',mdl) if mdl.Parent ~= workspace then findParent(mdl.Parent) elseif mdl.Parent == workspace then print('>>>',mdl) return mdl end end
print(findParent(game.Workspace.Player1.Torso).Name)
It prints Player1, which is what I want, but it returns nil. Why does it return nil? |
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 16 Jun 2016 02:28 PM |
remove .Name, you're attempting to find the parent of a string
Formerly ToxicDominator - add 17,509 posts | :(){:|:&};: |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 16 Jun 2016 02:31 PM |
| Yeah, it still doesn't work. |
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 16 Jun 2016 02:35 PM |
I just tested it and it works fine for me
Formerly ToxicDominator - add 17,509 posts | :(){:|:&};: |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 16 Jun 2016 02:38 PM |
function findParent(mdl) print('>>',mdl) if mdl.Parent ~= workspace then findParent(mdl.Parent) elseif mdl.Parent == workspace then print('>>>',mdl) return mdl end end
x = game.Workspace:FindFirstChild(findParent(game.Workspace.Model.Part)) print(x)
What does it return? I was hoping I could obtain the model or something. |
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 16 Jun 2016 02:41 PM |
it's supposed to print an ancestry tree of the specified object (except Workspace), correct?
Formerly ToxicDominator - add 17,509 posts | :(){:|:&};: |
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 16 Jun 2016 02:44 PM |
by the way you should be using:
function findParent(mdl) print('>>',mdl) if mdl.Parent ~= workspace then findParent(mdl.Parent) elseif mdl.Parent == workspace then print('>>>',mdl) return mdl end end
print(findParent(game.Workspace.Model.Part))
which printed this for me:
>> Part >> Model >>> Model
Formerly ToxicDominator - add 17,509 posts | :(){:|:&};: |
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 16 Jun 2016 02:54 PM |
That's what it prints inside, but it doesn't return any value. If you take out print,
function findParent(mdl) print('>>',mdl) if mdl.Parent ~= workspace then findParent(mdl.Parent) elseif mdl.Parent == workspace then print('>>>',mdl) return mdl end end
findParent(game.Workspace.Model.Part)
It would still print out those values, but when you check to see what it returns, it doesn't print anything.
|
|
|
| Report Abuse |
|
|
Raphael7
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
| |
|