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

Script to remove all head parts?

I need a script that will remove your head and hats/accessories. Including the face. This is the script I have here right now but doesn't get rid of the hair or face:

function onTouched(hit) 
	local d = hit.Parent:GetChildren() 
	for i=1, #d do 
		if (d[i].className == "Accessory") then 
			d[i]:remove() 
		end 
	end
end 

script.Parent.Touched:connect(onTouched) 

Any way to get rid of the hair and face from the head with this script? It just isn't working. Thanks!

2 comments

0

To simplify your life, call :RemoveAccessories on the Character's Humanoid. http://wiki.roblox.com/index.php?title=API:Class/Humanoid/RemoveAccessories. Then, just look for the Character's head, and remove the face manually by checking for any decals.

0

It is a morph button that will turn me into something <-- that works, then it will remove all the accessories (hair, hat) and face (decal face) <-- which doesn't work. It just stays there.

1 answer

Well we need to do this in 3 steps, remove accessories, remove hats, and then remove the face.

First we can use the RemoveAccessories() function on the humanoid to remove accessories

local character = workspace.Player

character:WaitForChild("Humanoid"):RemoveAccessories()

Next we will make a for loop to remove all hats

local character = workspace.Player

character:WaitForChild("Humanoid"):RemoveAccessories()
for _,v in pairs(character:GetChildren()) do
	if v:IsA("Hat") then
		v:Destroy()
	end
end

Lastly we remove the face, the face is a decal inside the head

local character = workspace.Player

character:WaitForChild("Humanoid"):RemoveAccessories()
for _,v in pairs(character:GetChildren()) do
	if v:IsA("Hat") then
		v:Destroy()
	end
end
character:WaitForChild("Head").face:Destroy()

If you don't want to use the function for accessories we can add it to the for loop

local character = workspace.Player

for _,v in pairs(character:GetChildren()) do
	if v:IsA("Hat") or v:IsA("Accessory") then
		v:Destroy()
	end
end
character:WaitForChild("Head").face:Destroy()

19 comments

0

Sorry, forgot to add it is a morph button. It will turn you into a piece of bread and make all body parts invisible <-- which works. But then when it gets to the head parts (face, accessories/hats), it doesn't disappear. So this thing isn't working for some reason.

0

@Kinq_Perfect then just replace your remove part with this and edit it

0

I copied it into a script and put it in workspace. and the face disapeared successfully but the hair stayed on.

0

The other script with the non-function for accessories will do the same thing: Remove the face but not the hair.

0

lol Just use the FindFirstChildOfClass function for the face. XD (Head:FindFirstChildOfClass('Decal'):Destroy())

0

I said the face disappears succesfully but not the hair. I need something to remove the hair.

0

@TheeDeathCaster how is using that function any easier than using .face, and how is that even funny

0

I still need the script for removing the hair too. The face is done though.

0

please help

0

@Kinq_Perfect show pic of children in character after script runs

0

https://gyazo.com/28cabe97341babe4f5e5453b643b9eeb this is it, the "Chest" model is what the morph needs to have to morph into. so don't mind it.

0

https://gyazo.com/1d829b1ab59b6e1e7af41a55bfe02dcb this is what I look like too when I touch the morph button. just the hair is left.

0

@DanzLua It's a habit. :P As for how it's easier, it'll check all the children's ClassNames until it gets a hit, regardless of the object's name; I found this function to be very helpful. ^^

0

@TheeDeathCaster yes but it will only find the first one, as for the loop it'll go through each child, it doesn't make it any easier to find them all

0

@Kinq_Perfect I don't know what to say, the script I provide should remove both hats and accessories

0

@DanzLua I'm talkin about the face silly, not the hats. :P

0

@TheeDeathCaster oh ;p still the decal is named face and really why name it anything different

0

@DanzLua Idk; Never hurts to be careful.

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