generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: FindFirstParent function

Previous Thread :: Next Thread 
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 07:01 PM
I was kind of bored, so I decided to make a FindFirstChild-type function, except for parents rather than children. Since it will probably be useful to just about every scripter at one time or another, I decided to share it with you all. ;)

The name would probably make you expect it to see if the parent of an object's name is a certain string. However, that is not the case, as that would be useless. It will keep searching the object's ancestors until it finds an object with the specified name.

function FindFirstParent(obj, name) --Declares function as well as two parameters
local result = obj --Declares local variable named 'result'
repeat --Initiates repeat loop
result = result.Parent --Sets result's value to its Parent
if not result then --If the new result does not exist
return nil --Return nil (duh)
end --End if statement
until result.Name == name --End repeat loop when a match is found
return result --Return result (again, duh)
end --End function

It is used the same way as FindFirstChild, except since it's a function, not a method, you don't run it ON the object. Here is an example:

local m = Instance.new("Model", workspace)
local p = Instance.new("Part", m)
local mesh = Instance.new("SpecialMesh", p)
p.Anchored = true
local model = FindFirstParent(mesh, "Model")
if model then
Instance.new("Message", workspace).Text = model.Name .. " has been found."
end

Enjoy. ;)
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 07:20 PM
Bump. Not even people have seen this.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 07:20 PM
enough*
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 07:48 PM
Bump.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 08:02 PM
y u no reply?
Report Abuse
jtfriend137 is not online. jtfriend137
Joined: 19 Jul 2010
Total Posts: 1960
25 Jul 2012 08:06 PM
Oh hai.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 08:06 PM
...Wow, thanks for the reply. :C
Report Abuse
pokemon771 is not online. pokemon771
Joined: 28 Oct 2008
Total Posts: 8671
25 Jul 2012 08:11 PM
This too hard for da forum. :o
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 08:13 PM
@pokemon - Too hard? I think not. It's just a function, a variable, and a repeat loop. Besides, this isn't meant to teach people, it's to help them.
Report Abuse
pokemon771 is not online. pokemon771
Joined: 28 Oct 2008
Total Posts: 8671
25 Jul 2012 08:14 PM
It was a joke.
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 09:02 PM
Bump. :/
Report Abuse
nightmare3o is not online. nightmare3o
Joined: 21 Jun 2008
Total Posts: 956
25 Jul 2012 09:06 PM
This is to complicated for me.
I'm gonna go look for some ice cream.

The scripty stuff looks cool though :|
Report Abuse
Strieken is not online. Strieken
Joined: 17 Jun 2011
Total Posts: 3058
25 Jul 2012 09:07 PM
unless you had an object that was buried deeeeeeep inside a model filled with tons of other objects and stuff, this wouldn't be all that useful.

i do think its a good idea though.

btw

hi
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
25 Jul 2012 09:08 PM
An object can only have one parent, derp.
Report Abuse
Strieken is not online. Strieken
Joined: 17 Jun 2011
Total Posts: 3058
25 Jul 2012 09:09 PM
@thek00lkid

are you stupid?

an object can have a parent, and then that parent can have a parent, and so forth.

"derp".
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 09:10 PM
It would allow you to check if it has a certain parent, and not to mention you wouldn't have to go doing "script.Parent.Parent.Parent.Parent" every time you want to index a parent.

and hi
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 09:11 PM
@thek00lkid - Yeah, I know you're not stupid, but you should have read the whole post. :P
Report Abuse
Cenort is not online. Cenort
Joined: 20 Nov 2009
Total Posts: 9679
25 Jul 2012 09:14 PM
model = game.Workspace.Model22

skateboard = script.Parent

--we need to find if skateboard is a descendent of model

print(model:IsAncestorOf(skateboard))

voila.
Report Abuse
Strieken is not online. Strieken
Joined: 17 Jun 2011
Total Posts: 3058
25 Jul 2012 09:17 PM
^

BUT THAT'S NOT AS FUNNNN
Report Abuse
thek00lkid is not online. thek00lkid
Joined: 18 Jun 2011
Total Posts: 2778
25 Jul 2012 09:18 PM
Oh, well, it's inefficient to have that many parents anyhow! XD

Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 09:22 PM
@Cenort - That is irrelevant. That method tells if an object is an ancestor of another object. This function FINDS an ancestor of an object.
Report Abuse
Cenort is not online. Cenort
Joined: 20 Nov 2009
Total Posts: 9679
25 Jul 2012 09:24 PM
why would you know the name of the ancestor but not be able to access it?... very odd situation.
Report Abuse
iAdobe is not online. iAdobe
Joined: 22 May 2011
Total Posts: 367
25 Jul 2012 09:26 PM
[ Content Deleted ]
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Jul 2012 09:27 PM
What if you don't know that it's an ancestor? What if you don't know its name (variables)? What if you simply do not want to repeatedly type ".Parent.Parent.Parent"?
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
26 Jul 2012 03:11 PM
Bump. c-:
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image