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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|