Exclude something from a _, v in pairs loop

Hey i have been coding a barrage and a ragdoll script the barrage uses attachments for trails and the route it needs to go but the ragdoll script deletes them how can I tell it to not delete my stands parts

	local function ragdoll(c)
		c.Humanoid.PlatformStand = true
		for _, v in pairs(c:GetDescendants()) do
			if v:IsA("Motor6D") then
				local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
				a0.CFrame = v.C0
				a1.CFrame = v.C1
				a0.Parent = v.Part0
				a1.Parent = v.Part1

				local b = Instance.new("BallSocketConstraint")
				b.Attachment0 = a0
				b.Attachment1 = a1
				b.Parent = v.Part0

				v.Enabled = false
				for e, v in pairs(c:GetChildren()) do
					if v:IsA("Part") then
						v.CanCollide = true
					end
				end
			end
		end
		c.Head.CanCollide = true
		c.HumanoidRootPart.CanCollide = false
	end
	
	local function unragdoll(c)
		c.Humanoid.PlatformStand = false
		for _, motors in pairs(c:GetDescendants()) do
			if motors:IsA("Motor6D") then
				motors.Enabled = true
			end
		end
		for _, v in pairs(c:GetDescendants()) do
			if v:IsA("BallSocketConstraint") or v:IsA("Attachment") then
				v:Destroy()
			end
		end
	end

To the related Instances you can add a label with CollectionService and with HasTag verify that it has it so as not to delete it

if v:IsA("Motor6D") and not game:GetService("CollectionService"):HasTag(v, Tag) then

replace Tag with the tag you want to place on it

2 Likes

If you’re trying to exclude something from a in pairs loop, then you can check for the names of what you DON’T want included within the loop.
Example:

for i, v in pairs(Table) do
 if v == "1st thing you dont want in your loop" or "this thing you dont want in your loop" or "etc" then
  print("dont include in loop" .. v)
 end
end