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 » Scripters
Home Search
 

Re: How to modify children? "i, v in pairs do" style

Previous Thread :: Next Thread 
Craftwithcookie is not online. Craftwithcookie
Joined: 21 Dec 2012
Total Posts: 951
17 Nov 2016 10:15 PM
So say I got a model in Work space with parts in it, and another model in it for fun

Work space >
Model >
Wood >
Wood >
Door >
Doorframe >
Doorframe >
Doorself >
Wood >
Stone >

I know you can ClearAllChildren() but how do you make all the parts in the model get a transparency of 1 and can't collide. If the answer isn't simple, its okay I have an "Alternative" plan for my scheme...
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
17 Nov 2016 10:17 PM
for _, Obj in pairs(workspace.Model:GetChildren()) do
if Obj:IsA("BasePart") then
Obj.Transparency = 1
Obj.CanCollide = false
end
end
Report Abuse
Salinas23 is not online. Salinas23
Joined: 28 Dec 2008
Total Posts: 37141
17 Nov 2016 10:18 PM
As far as I know you'd have to use a GetChildren() function, a for loop, and an if condition check for models inside models inside models.

Easiest thing to do would be to try using GetExtentSize(), convert it to Region3 somehow, and check for every part inside that region3

I have a spider on my back.
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
17 Nov 2016 10:19 PM
If you wanted to get the parts in the sub model, you'd have to use recursion.

http://wiki.roblox.com/index.php?title=Recursion
Report Abuse
Praefor is not online. Praefor
Joined: 14 Nov 2016
Total Posts: 258
17 Nov 2016 10:40 PM
1.) Transparent parts are bad for performance.

2.)

local function applyToDescendants(object, callback)
for _, child in pairs(object:GetChildren()) do
callback(child)

applyToDescendants(child, callback)
end
end

applyToDescendants(workspace.Model, function(child)
if child:IsA("BasePart") then
child.Transparency = 1
end
end)




Report Abuse
Craftwithcookie is not online. Craftwithcookie
Joined: 21 Dec 2012
Total Posts: 951
17 Nov 2016 10:42 PM
@praefor
I decided that I am gonna do a better way, not have invisible parts.
But thanks guys for the tips anyways! I may need it in the future
Report Abuse
Salinas23 is not online. Salinas23
Joined: 28 Dec 2008
Total Posts: 37141
17 Nov 2016 11:03 PM
wait... is that a function calling the same function it is inside of?!?
A dream within a dream... We must go deeper.

I have a spider on my back.
Report Abuse
Praefor is not online. Praefor
Joined: 14 Nov 2016
Total Posts: 258
17 Nov 2016 11:14 PM
It's a technique known as "recursion", yep.


Report Abuse
Salinas23 is not online. Salinas23
Joined: 28 Dec 2008
Total Posts: 37141
18 Nov 2016 05:33 AM
That is actually really amazing and helpful and omg I cant wait to apply it on my game

I have a spider on my back.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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