Deleting added children

Hello, I’m making a game where players unlock a bunch of different auras and each aura has different particles and stuff in different parts of the player. For example one aura may add attachments only to the humanoid root part and another aura may add attachments to each leg and arm, the torso and the head. Now when a player equips a different aura I need to remove all the added attachments from the last aura. I tried doing player:LoadCharacter() and player:LoadCharacterWithHumanoidDescription() but neither of these seemed to remove the attachments. How might I achieve this (without resetting or killing the player, they need to remain at the same position)?

3 Likes

can’t you use a tool.Equipped event by making the aura a child of a tool and then just doing :GetChildren() if the parts are children of the aura? if they’re in different hiearchies you can use getdescendants or collectionservice too.

I haven’t considered adding them to a tool no, I should have been more specific in my post but the ‘parts’ are mostly particle emitters and attachments.

To emphasize on your request to ‘delete’ the children, I can think of a hacky solution off the top of my head.

When you add all the attachments and effects, simply give them a distinctive name that makes it easy to differentiate. For instance, name them all after the aura that’s being equipped. When you want to delete them you can simply iterate through the character:GetChildren() (or character:GetDescendants() if necessary) using a for .. do loop. When the name of the instance matches the name of the aura’s, delete them.


Example:

for _, v in character:GetChildren() do
	if v.Name == "AuraName" then
		v:Destroy()
	end
end
1 Like

Actually that should work, one second I’ll try that.

That worked perfectly thank you so much.

for i, v in pairs(plr.Character:GetChildren()) do
		for i2, v2 in pairs(v:GetChildren()) do
			if v2.Name == AuraName then
				v2:Destroy()
			end
		end
		
	end

My bad. Sorry I’m typing a bit longer now so the message can be sent.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.