I am trying to eliminate players hat, or in mine case, hair. But it doesnt appears to work. I have actually a morth kind of thing that when you touch a brick (button) it provides my body invisible and also sticks random bricks on the human body to do an armor or something.

You are watching: How to take off your hat in roblox

function onTouched(hit) regional d = hit.Parent:GetChildren() because that i=1, #d do if (d.className == "Hat") climate d:remove() finish endend script.Parent.Touched:connect(onTouched)How ever the hair continues to be on my head and doesn`t gets removed. Any kind of ideas please?Thank you.


4 answers


Log in come vote
2
Answered by
*
Astralyst 389
3 years back
Edited 3 year ago

https://wiki.roblox.com/index.php?title=API:Class/Accessory

Don"t use "Hat", use "Accessory".

if (d:IsA("Accessory")) climate d:Destroy()also, use :IsA instead of .className ==


0
wait, className? Astralyst 389 — 3y
1
http://wiki.roblox.com/index.php?title=API:Class_reference Adv3rtizement 101 — 3y
0
Oh thanks. Yeah ns will settle it right now. I didnt know hair wasnt a "hat", ns thought everything on her head is a hat. HeyItzDanniee 252 — 3y
0
Just a brand-new comment. The worked. The morth gotten rid of my hair. Give thanks to you astrawr. :D HeyItzDanniee 252 — 3y
View every comments (5 more)
1
Note the accessories aren"t simply hats! They are wings, and also all those points you deserve to put on her player. If you want to see for yourself, just press play and look in your player model! Adv3rtizement 101 — 3y
2
You need to not it is in using eliminate in your code and also Hats still exist however most use Accessories. User#5423 -5 — 3y
0
You can debug that script by checking if the y value of the Accessory is an ext than the y value of the Character"s head. Just something come think about. DeceptiveCaster 3746 — 3y
0
Bad what if over there is an accessory the is not a hat nc2r 117 — 2y
0
Bad what if there is one accessory that is no a cap nc2r 117 — 2y
*

Log in come vote
1
Answered by
*
ee0w 458
3 years back
Edited 3 years ago

You might iterate v the character and destroy every Accessory instance.

for i, v in pairs(character:GetChildren()) carry out if v:IsA("Accessory") climate v:Destroy() endendBe certain to Upvote/Accept if ns helped!


0
This would eliminate all accessories from the player not simply hats. User#5423 -5 — 3y
Log in come vote
1
Answered by
*
User#5423 -5
3 years earlier
Edited 3 years ago

Roblox converted hats to equipment so you need to be using the new attachement system.

The new system functions by attaching the very same name attachment v the one in the players character so you can not easily specify what is a hat.

The best method would it is in to straightforward check i beg your pardon accessories usage the attachments in the football player head by checking the name.

Lastly carry out not usage remove() together it is deprecated usage Destroy()

Example just removing hats and also accessories which usage the football player head attachments.

See more: How Much Is 2 Pounds Of Chicken ? How Many Cups Is 2 Lbs Cooked Chicken

-- perform of attachments names come removelocal nameList = FaceCenterAttachment = true, FaceFrontAttachment = true, HairAttachment = true, HatAttachment = truescript.Parent.Touched:Connect(function(hit) for i, v in pairs(hit.Parent:GetDescendants()) carry out if v:IsA("Accessory") then -- recursivly look because that a kid which is a attachments local connect = v:FindFirstChildWhichIsA("Attachment", true) -- examine that the surname is in the list ie only ruin hats if attach and also nameList then v:Destroy() print("print removed", v) finish -- legacy check some models use old hats elseif v:IsA("Hat") then v:Destroy() end endend)Hope this helps.