Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get descendants of all players in workspace?

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

5 comments

0

Do you mean get all of the players' character in 'workspace'?

0

Yes

0

Get all of the descendants of a player's character in workspace?

0

Yes

0

let's talk in Community Chat

2 answers

✓ Accepted 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

2 comments

0

thanks

0

Please also denote that Instance:GetChildren() does not traverse into the descendants tree.

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

1 comment

0

You're using ipairs incorrectly.

This discussion is preserved as it was. New answers, comments, and votes are closed.