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

Needing help on how to fix this code to delete accessory's and the face?

for _, item in pairs (character:GetChildren()) do
	print("start")
    if item.ClassName == "Part" then
        item.Transparency = 1
	elseif item.Name == "Head" then
		item:FindFirstChild("face"):Destroy()
	elseif item.ClassName == "Accessory" then
		print("accessory")
		item:Destroy()
	end
end

this code deletes the body parts but doesn't delete the face or the accessory's on the player, the body type is R6 and i was wondering if anybody could fix the code so it deletes the players face and accessory's which will basically make the player invisible. I have also tried to use some of the 'fixes' found on this site but they don't work, the script is a local script in StarterCharacterScripts, also please note that "accessory's" does not print.

2 answers

✓ Accepted answer

Since it’s under StarterCharacterScripts, we can access the Character using script.Parent.

wait()
script.Parent.Humanoid:RemoveAccessories()

script.Parent.Head:FindFirstChildOfClass("Decal"):Destroy()

No for loop needed to remove the accessories.

I had this problem recently. I'm not entirely sure why, but it's a good idea to delete the face of the character (and, though untested, likely accessories as well) through the server and not a LocalScript. Then within a LocalScript, if you want to include a new face/accessories, it should be fine to create them locally.

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