I am trying to eliminate players hat, or in mine case, hair. But it doesnt seems to work. I have a morth form of thing that as soon as you touch a brick (button) it provides my human body invisible and also sticks arbitrarily bricks ~ above the human body to make an armor or something.

You are watching: How to take off hats in roblox

function onTouched(hit) regional d = hit.Parent:GetChildren() for i=1, #d execute if (d.className == "Hat") then d:remove() end endend script.Parent.Touched:connect(onTouched)How ever the hair continues to be on mine head and doesn`t gets removed. Any type of ideas please?Thank you.


4 answers


Log in come vote
2
Answered by
*
Astralyst 389
3 years earlier
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, usage :IsA rather 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 i will fix it right now. Ns didnt understand hair wasnt a "hat", i thought every little thing on her head is a hat. HeyItzDanniee 252 — 3y
0
Just a new comment. The worked. The morth eliminated my hair. Say thanks to you astrawr. :D HeyItzDanniee 252 — 3y
View every comments (5 more)
1
Note that accessories aren"t simply hats! They space wings, and all those points you can put on her player. If you desire to check out for yourself, simply press play and also look in your player model! Adv3rtizement 101 — 3y
2
You have to not be using remove in your code and also Hats still exist but most use Accessories. User#5423 -5 — 3y
0
You can debug that manuscript by checking if the y value of the Accessory is much more than the y value of the Character"s head. Simply something to think about. DeceptiveCaster 3761 — 3y
0
Bad what if over there is an accessory that is no a cap nc2r 117 — 2y
0
Bad what if there is an accessory that is not a cap nc2r 117 — 2y
*

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

You can iterate through the character and also destroy every Accessory instance.

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


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

Roblox convert hats to equipment so you should be using the new attachement system.

The brand-new system works by it is registered the exact same name attachment v the one in the football player character so you cannot easily define what is a hat.

The best method would be to basic check i m sorry accessories usage the attachments in the football player head by check the name.

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

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

See more: What Is The Amount Of Heat Needed To Raise The Temperature Of 1 Kilogram Of Water 1 Degree Celsius.

-- perform of attachments names come removelocal nameList = FaceCenterAttachment = true, FaceFrontAttachment = true, HairAttachment = true, HatAttachment = truescript.Parent.Touched:Connect(function(hit) because that i, v in pairs(hit.Parent:GetDescendants()) carry out if v:IsA("Accessory") climate -- recursivly look for a son which is a attachments local attach = v:FindFirstChildWhichIsA("Attachment", true) -- examine that the surname is in the perform ie only destroy hats if attach and nameList climate 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.