How to get certain parts of a model

I have used GetDescendants and GetChildren but I would only like to get certain parts of a model such as in a character. This is best I have got but it would only get the humanoid root part. I would appreciate help since I don’t want to create certain attachments for each body part.

for _, limbs in pairs(character:GetChildren()) do
				if limbs.Name == ("HumanoidRootPart") or limbs.Name == ("Head") or limbs.Name == ("RightUpperArm") or limbs.Name == ("LeftUpperArm") or limbs.Name == ("LeftUpperLeg") or limbs.Name == ("RightUpperLeg") then
					Attach = Instance.new("Attachment", limbs)
					Attach2 = Instance.new("Attachment", limbs)
					Attach.Visible = true
					Attach2.Visible = true
					Attach2.Position = Vector3.new(0, 0, 2.5)
				end
			end

You can reference Character limbs as BaseParts. Example:

for _, Obj in pairs(Character:GetChildren()) do
    if Obj:IsA("BasePart") then
        --limb things here
    end
end
2 Likes

How would this work with choosing certain parts like left upper leg , right upper leg, and root part?

Since it would still only add in on the root part if I add my thing after yours.

An alternative could be this:

local allowed = {
"HumanoidRootPart";
"Head";
"LeftUpperArm";
}

for _, Obj in pairs(Char:GetChildren()) do
    if table.find(allowed, Obj.Name) ~= nil then
        --do stuff on selected parts mentioned in table
    end
end

1 Like

It was working before but yours works as welll but when I try adding a part trail it would just put it one the root part? I am confused why it would do that with a part trail.

Where did you add the trail? Also, are you using the table method or the BaseParts method?

It was the table method I added it outside and inside the loop.

local allowed = {
	"HumanoidRootPart";
	"Head";
	"RightUpperArm";
	"LeftUpperArm";
	"LeftUpperLeg";
	"RightUpperLeg"
}

for _, limbs in pairs(character:GetChildren()) do
				if table.find(allowed, limbs.Name) ~= nil then
					Attach = Instance.new("Attachment", limbs)
					Attach2 = Instance.new("Attachment", limbs)
					Attach.Visible = true
					Attach2.Visible = true
					Attach2.Position = Vector3.new(0, 0, 2.5)
					Debris:AddItem(Attach, 9)
					Debris:AddItem(Attach2, 9)
					--[[while wait(0.1) do
						local startPart = Attach.WorldPosition
						local endPart = Attach2.WorldPosition + Vector3.new(0,0,2.5)
							CreatePoints(startPart, endPart, 3, model)
                              Debris:AddItem(model, 9)
					end]]
				end
				while wait(0.1) do
					local startPart = Attach.WorldPosition
					local endPart = Attach2.WorldPosition + Vector3.new(0,0,2.5)
					CreatePoints(startPart, endPart, 3, model)
				end
				Debris:AddItem(model, 9)

The create points is just for the part trail effect.

1 Like

Well if the name of the trail matches the names mentioned in the table, it will get passed as true. Change the name of the trail to something unique compared to the parts mentioned in the table.

Thanks I will try it out tomorrow.

What do you mean match the names in the table and something unique how would that help?? Since I need to add it to all chosen body parts, and it is just a part effect parented to a folder in workspace.

I am just a little confused on what you mean by changing the name how would it affect it?

Where is the trail located? ----

Parented? it is a folder called model.

Do you want the trail to be included in the loop?

Yes since taking it out of the loop will result in just choosing root part or a random part but showing all the attachments.

If you want it to be included in the loop, just add the trail name in the table and do Character:GetDescendants() instead.

But why descendants the folder is not going to be parented to the limbs
and also for some reason it would not delete the model it would just stop.

		model = Instance.new("Folder")
		model.Name = "Points"
		model.Parent = workspace	
		local character = Tool.Parent
		local humanoid = character:WaitForChild("Humanoid")
		local rootpart = character:WaitForChild("HumanoidRootPart")
		if humanoid and rootpart then
			for _, limbs in pairs(character:GetChildren()) do
				--if limbs:IsA("BasePart") then
				if table.find(allowed, limbs.Name) ~= nil then
					Attach = Instance.new("Attachment", limbs)
					Attach2 = Instance.new("Attachment", limbs)
					Attach.Visible = true
					Attach2.Visible = true
					Attach2.Position = Vector3.new(0, 0, 5)
					Debris:AddItem(Attach, 9)
					Debris:AddItem(Attach2, 9)
					--[[while wait(0.1) do
						local startPart = Attach.WorldPosition
						local endPart = Attach2.WorldPosition 
							CreatePoints(startPart, endPart, 3, model)]]
				end
			end
			while wait(0.1) do 
				local startPart = Attach.WorldPosition
				local endPart = Attach2.WorldPosition 
				local segments = 3
				--LightningDecor(startPart, endPart, segments ,model)
				CreatePoints(startPart, endPart, 3, model)
			end
			Debris:AddItem(model, 9)
		end