|
| 14 Jul 2011 10:22 AM |
function Count(Group) number = 0 G = Group:GetChildren() for i=1, #G do if G[i].ClassName == "Model" then number = number + Count(G[i]) end if G[i].ClassName == "Part" then number = number + 1 end return number end end
print("Found "..Count(Workspace).." parts in the workspace")
Even though it is searching the models too, it always prints "0" |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2011 10:27 AM |
function Count(Group) number = 0 G = Group:GetChildren() for i=1, #G do if G[i].ClassName == "Model" then number = number + 1 end if G[i].ClassName == "Part" then number = number + 1 end return number end end
print("Found "..Count.." parts in the workspace")
you never Defind Count, The only count i see is the Function Count() thats all i see.
|
|
|
| Report Abuse |
|
|
|
| 14 Jul 2011 12:28 PM |
| I don't want it to check the models, I want it to search them for parts. I'm counting how many blocks are in the game. |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2011 12:30 PM |
Lemme fill in what that script does.
function Count(nil) --never defined a variable for Group, so its nil number = 0 G = Group:GetChildren() --returns 0 children, nil doesnt have children for i=1, 0 do --never runs if G[i].ClassName == "Model" then number = number + 1 end if G[i].ClassName == "Part" then number = number + 1 end return number --returns 0 end end
|
|
|
| Report Abuse |
|
|
|
| 14 Jul 2011 12:36 PM |
function CountChildren(children) parts = {} for i = 1, #children do if children[i]:IsA("BasePart") then table.insert(parts, children[i]) end if children[i]:IsA("Model") then a = children:getChildren() for i = 1, a[i] do table.insert(parts, a[i]) end end end return #parts end
numparts = CountChildren(game.Workspace:getChildren())
print(numparts) |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2011 12:38 PM |
I'm confused. If I write something like: function Change(Hi) Hi.Name = "Hello" end
Change(game.Workspace.Model)
Wouldn't it change the model's name to Hello? Do I need to actually put Hi = game.Workspace.Model |
|
|
| Report Abuse |
|
|
agent767
|
  |
| Joined: 03 Nov 2008 |
| Total Posts: 4181 |
|
|
| 14 Jul 2011 12:38 PM |
function Count(Group) number = 0 G = Group:GetChildren() for i=1, #G do if G[i].ClassName == "Model" then number = number + Count(G[i]) end if G[i].ClassName == "Part" then number = number + 1 end end return number end
print("Found "..Count(Workspace).." parts in the workspace") |
|
|
| Report Abuse |
|
|
| |
|
|
| 14 Jul 2011 01:13 PM |
function check(hi) g = hi:GetChildren() for i = 1, #g do print g[i].Name end end
check(game.Workspace)
function check(hi) for i = 1, #hi do print hi[i].Name end end
check(game.Workspace:GetChildren())
Difference? |
|
|
| Report Abuse |
|
|
|
| 14 Jul 2011 01:27 PM |
| No difference, they'll do the same thing. Except you already used 'getChildren()' when you fire up the function and the other you call 'getChildren' in the function. |
|
|
| Report Abuse |
|
|