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

How would I find the player's parts by loops?

I am trying to detect one of the humanoid parts of a player, however I don't know where to approach to this.

In line 1, I don't want to use workspace.Player1. Is there a better way of doing this inside a LocalScript?

--LocalScript
for _, player in pairs(workspace.Player1:GetDescendants()) do
	if player:IsA("Part") or player:IsA("MeshPart") then
		print(player.Name)
	end
end

2 answers

✓ Accepted answer

By just saying:

local Children = workspace.Player1:GetChildren()

for _, player in pairs(Children) do
	if player:IsA("Part") or player:IsA("MeshPart") then
        print(player.Name)
    end
end

This would be a better approach to it but it really does not matter how you right it. Using variable will be better though in the future if you need to refer to them again.

---Variables----
Player = game.Players.LocalPlayer
Character = workspace:WaitForChild(Player.Name)
-------------------

---Stuff-----------
for i, v in pairs(Character:GetChildren()) do
	if v:isA("BasePart") then
		print(v.Name.." Is a Part :D")
	end
end

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