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

How to get descendants of all players in workspace? [closed]

Asked by 4 years ago
Edited 4 years ago

How to get descendants of all players in workspace? Like humanoid, pants, shirt, parts, etc.

0
Do you mean get all of the players' character in 'workspace'? DiamondComplex 285 — 4y
0
Yes Velcorii 13 — 4y
0
Get all of the descendants of a player's character in workspace? DiamondComplex 285 — 4y
0
Yes Velcorii 13 — 4y
0
let's talk in Community Chat DiamondComplex 285 — 4y

Closed as Not Constructive by Ziffixture

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

Here's the code for you:

for _,player in pairs(game.Players:GetPlayers()) do

    local playerCharacter = player.Character--Their Character in Workspace

    for _,playerDescendant in pairs(playerCharacter:GetChildren()) do
        --Code for the descendants
        --something something


    end

end

0
thanks Velcorii 13 — 4y
0
Please also denote that Instance:GetChildren() does not traverse into the descendants tree. Ziffixture 6913 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

do this:

local assets = {}

for _, player in ipairs(game.Players:GetPlayers()) do
    table.insert(assets, player.UserId)
    assets[player.UserId] = player.Character:GetDescendants()
    wait()
end

game.Players:GetPlayers() to get players, insert the userid into the table, then the userid value is a table containing all the contents of player:GetDescendants() I added a wait() function to prevent server crashing. Btw, you can print the assets by doing

for playerUserId, instances in pairs(assets) do
    for _, instanceNames in ipairs(instances) do
        print(instanceNames)
    end
    wait()
end
0
You're using ipairs incorrectly. Ziffixture 6913 — 4y