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: basic question

Previous Thread :: Next Thread 
momomarshmallow is not online. momomarshmallow
Joined: 03 Oct 2010
Total Posts: 14347
06 Apr 2015 06:33 PM
I'm learning about tables now and they gave an example script to change all the parts of a model to a different color and this is what they gave:

ch = game.Workspace.MyModel:GetChildren() --ch stands for children. ":GetChildren" can also be written as ":getChildren"
for i = 1, #ch do
if ch[i].className=="Part" then --"className" is a property of every Roblox object. "Part" means that it is a brick.
ch[i].BrickColor=BrickColor.new("Black") --Every "Part" object has a "BrickColor" property. Trying to access the BrickColor property of a model would raise an error.
end
end

but my question just has to do with the second line; why are they using 'for i=1...'?
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
06 Apr 2015 06:38 PM
They were using the for loop to go through the table, and the i later on as the index of each of the parts in the model.

However, there is a much simpler way to do all of this, examine the following code:

local model = game.Workspace.MyModel

for _, child in pairs(model:GetChildren()) do
if child:IsA('BasePart') then
child.BrickColor = BrickColor.new('Black')
end
end
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