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 » Scripting Helpers
Home Search
 

Re: I'm testing a way to affect all parts in the workspace.

Previous Thread :: Next Thread 
DarthGamer6 is not online. DarthGamer6
Joined: 01 Nov 2008
Total Posts: 47
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
bikerking200 is not online. bikerking200
Joined: 11 Mar 2010
Total Posts: 5047
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
DarthGamer6 is not online. DarthGamer6
Joined: 01 Nov 2008
Total Posts: 47
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
buildthomas is not online. buildthomas
Joined: 05 Dec 2008
Total Posts: 715
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
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
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
DarthGamer6 is not online. DarthGamer6
Joined: 01 Nov 2008
Total Posts: 47
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 is not online. 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
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
14 Jul 2011 12:39 PM
@Darth

That would work.
Report Abuse
DarthGamer6 is not online. DarthGamer6
Joined: 01 Nov 2008
Total Posts: 47
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
deathman12e3 is not online. deathman12e3
Joined: 10 Nov 2009
Total Posts: 7284
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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