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 select specific parts using GetChildren()?

Previous Thread :: Next Thread 
Cynoid is not online. Cynoid
Joined: 07 Nov 2012
Total Posts: 8408
14 Jul 2017 10:07 PM
I am using this line to get the children of a model:

local parts = script.Parent.Parent:GetChildren()

Later in the script I use a Touched event that requires the parts value, which looks like this:

for i = 1, #parts do
-- so forth
end

My question is, I only want to change the BrickColor of the parts named "Wall1", how would I do that?

Thanks.
Report Abuse
doggy00 is online. doggy00
Joined: 11 Jan 2011
Total Posts: 3571
14 Jul 2017 10:10 PM
lol

You could either use what you have or use i,v in pairs (which is what I would do)

Script:


for i,v in pairs(parts) do

if v.Name == "Wall1" then

--code

end

end
Report Abuse
doggy00 is online. doggy00
Joined: 11 Jan 2011
Total Posts: 3571
14 Jul 2017 10:11 PM
Oh and if you were to use what you have, then you'd just do

if parts[i].Name == "Wall1" then

--code

end
Report Abuse
Cynoid is not online. Cynoid
Joined: 07 Nov 2012
Total Posts: 8408
14 Jul 2017 10:15 PM
Thank you so much, I'll try to use i,v in pairs next time.
Report Abuse
doggy00 is online. doggy00
Joined: 11 Jan 2011
Total Posts: 3571
14 Jul 2017 10:16 PM
You're welcome. When it comes to things like this, I'm not sure which is more 'efficient', but I pretty much always use i,v in pairs.
Report Abuse
Crimsonal is not online. Crimsonal
Joined: 23 Apr 2011
Total Posts: 1795
14 Jul 2017 10:20 PM
for name = start,end,inc do

is faster than pairs
Report Abuse
vastqud is not online. vastqud
Joined: 10 Sep 2011
Total Posts: 2464
14 Jul 2017 10:21 PM
i,v makes more sense to me, i get kind of confused when i see a script do it the other way


Report Abuse
Crimsonal is not online. Crimsonal
Joined: 23 Apr 2011
Total Posts: 1795
14 Jul 2017 10:21 PM
but for small scripts like that it doesn't really matter
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