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: GetChildren() question

Previous Thread :: Next Thread 
SpecterSlash is not online. SpecterSlash
Joined: 29 Aug 2009
Total Posts: 629
08 Jun 2014 03:56 AM
just a simple question guys!

this is how things go:
game.Workspace.Model.Part.Items --items is an object value

if i used game.Workspace:GetChildren()

will one of the children be the Part or Items?
if not, how do I make it search for the children of the children.
Report Abuse
YeahNick is not online. YeahNick
Joined: 28 Feb 2009
Total Posts: 2536
08 Jun 2014 04:02 AM
:GetChildren() returns a table of an object. If you did Workspace:GetChildren() then 'Model' would be in that table. For your instance you would need game.Workspace.Model:GetChildren(), although 'Items' would not be a direct child, because its parent is not 'Model'.
Report Abuse
SpecterSlash is not online. SpecterSlash
Joined: 29 Aug 2009
Total Posts: 629
08 Jun 2014 04:03 AM
But what if i want to get ALL the children of workspace? is there some sort of function like getchildren like that?
Report Abuse
SpecterSlash is not online. SpecterSlash
Joined: 29 Aug 2009
Total Posts: 629
08 Jun 2014 04:05 AM
basically what im trying to do right now is i have a model with lots of models with parts inside, i want to get all the children of the main model.

Main Model
(inside main model)
model with parts
model2 with parts
model3 with parts

how do i use any function that will get ALL the children of mainmodel including all its parts.
Report Abuse
YeahNick is not online. YeahNick
Joined: 28 Feb 2009
Total Posts: 2536
08 Jun 2014 04:10 AM
Sorry, but there isn't an easy method for that. Fortunately though, there's a user created method:

function GetDescendants(instance)
getfenv()['_d'] = {}
if (type(instance) ~= "userdata") or (not pcall(function() return instance['Name'] end)) then
error("GetDescendants requires an object.")
end
local function Get(parent)
for i,v in pairs(parent:GetChildren()) do
if (#v:GetChildren() > 0) then
Get(v)
end
end
end
Get(instance)
return _d
end

An example for use of this function would be this: local table = GetDescendants(Workspace)
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