Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make a script that gets EACH part in the game?

Asked by 10 years ago

So i am making random stuff, and i was testing something. And i found a problem with what i was doing. I can't make something that gets each 'game' part.

For example of what i mean:

I want a script that gets every item (class) present in the place. How do i do that? I will be glad when i find out. Thanks

0
This is not a request site, please post your attempted script. M39a9am3R 3210 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago

You can use the for statement to sort through children of the Workspace pretty easily.

Here's some code that will do what you're asking. I explained everything in comments.

a = game.Workspace:GetChildren() --Gets all of the Children of the workspace, regardless of ClassName.
bricks = 0 --This will change when the script finds bricks.

for i,v in pairs(a) do --Starts a for loop to run through the children of the workspace
    if v:IsA("Part") then --Checks if the Child of the workspace's ClassName is "Part".
    bricks = bricks + 1 --Adds 1 to the brick counter.
end
print(bricks) --When the script is done finding the Workspace's children, it will print the total number of bricks in the output.

Hope I helped!

0
Lol, thank you, that i already know. Read again, please. marcoantoniosantos3 200 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

If you want to get every single object in the workspace, then I suggest this:

local ObjectTable = {}
function GetObjects(Area)
    for _,Obj in pairs(Area:GetChildren() do
        table.insert(ObjectTable,Obj)
        GetObjects(Obj)
    end
end
GetObjects(game.Workspace)

This will make table ObjectTable contain every single object in the workspace. However, if you wanted every PART in the workspace, then you would slightly modify the script, like so:

local ObjectTable = {}
function GetObjects(Area)
    for _,Obj in pairs(Area:GetChildren() do
        if Obj:IsA("BasePart") then --This makes sure Obj is a brick
            table.insert(ObjectTable,Obj)
        end
        GetObjects(Obj)
    end
end
GetObjects(game.Workspace)

Hope this helped!

0
i want every part inside each part and each part and each part etc and in other services too. Thats what i mean by game! Please reply marcoantoniosantos3 200 — 10y
0
Yeah, this function will do that. Just replace the "game.Workspace" with "game" TurboFusion 1821 — 10y
0
already tried that marcoantoniosantos3 200 — 10y

Answer this question