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: How would I get the number of objects in workspace?\?

Previous Thread :: Next Thread 
flatlineyourlife is not online. flatlineyourlife
Joined: 26 Jul 2013
Total Posts: 85
27 Jul 2013 05:28 PM
I couldn't find any way/method so I ask how could I do so?
Report Abuse
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
27 Jul 2013 05:32 PM
Objects or parts?

function GetAmount(Parent, ClassName)
local Count = 0
local function Scan(parent)
for Index, Child in pairs(parent:GetChildren())
if Child:IsA(ClassName) or not ClassName then
Count = Count + 1
end
Scan(Child)
end
end
Scan(Parent)
end

print(GetAmount(Workspace)) --Everything
print(GetAmount(Workspace, "BasePart")) --Just parts
Report Abuse
flatlineyourlife is not online. flatlineyourlife
Joined: 26 Jul 2013
Total Posts: 85
27 Jul 2013 05:35 PM
That is relatively simple I should contemplate more before posting.
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
27 Jul 2013 05:51 PM
Might be a little better than Cody's (no offence o:)

function CAll(a,c)
local t = {}
for n,o in pairs(a:GetChildren())do
if(o:IsA(c))then table.insert(t,o)end
for nu,ob in pairs(CAll(o,c))do table.insert(t,ob)end
end
return t end

local parts = CAll(Workspace,"BasePart")
-- parts is now a table of all the parts in Workspace
print(#parts) -- Using the pound symbol on a table returns it's length, so #parts is how many parts are in Workspace
Report Abuse
fireblade2 is not online. fireblade2
Joined: 18 Nov 2007
Total Posts: 4666
27 Jul 2013 06:05 PM
For objects:

#workspace:GetChildren()


For objects of a specific class, use the above users' scripts.
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
27 Jul 2013 06:08 PM
#CAll(Workspace,"Instance") gets the count of every instance (object) in Workspace :p
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
27 Jul 2013 06:12 PM
ini = 1
recurse = function(n)
ini = ini + #n:GetChildren()
for _,v in pairs(n:GetChildren()) do recurse(v) end
end
recurse(Workspace)
print(ini)
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
27 Jul 2013 06:22 PM
Your code is impractical, Absur.
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
27 Jul 2013 06:24 PM
My code is perfectly practical for his intentions, and is more efficient than yours.
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
27 Jul 2013 06:26 PM
Tell me how it's more efficient, and it's impractical because everytime you want to run it you would have to set ini back to 0.
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
27 Jul 2013 06:49 PM
It's more efficient because I don't waste characters, lines and data on excess.
I don't see how setting ini back to 0 is a problem. You can render that as an appositive if you need that, it's not much of a problem.
Report Abuse
Java3D is not online. Java3D
Joined: 29 Jul 2012
Total Posts: 1229
27 Jul 2013 07:18 PM
You could return the number instead of using a global variable.
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
27 Jul 2013 07:22 PM
Absurdism's code finishes faster and executes everything quicker.
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