function onClicked(playerWhoClicked) local playerBody = game.Workspace[playerWhoClicked.Name] local d = playerBody.Parent:GetChildren() for i=1, #d do if (d[i].className == "Hat") then d[i]:remove() end end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
So, I wrote this script that should remove all of a player's hats. It doesn't output any errors, but it doesn't remove the hats.
if this helped, please be sure to accept my answer :) I have left some comments below.
function onClicked(playerWhoClicked) local playerBody = game.Workspace[playerWhoClicked.Name] -- or you could just do "playerWhoClicked.Character" local d = playerBody:GetChildren() -- You don't need to get the parent, you already have the character. for i=1, #d do if (d[i]:IsA("Hat") or d[i]:IsA("Accessory")) then -- "ClassName" is deprecated. You should also find a Accessory. d[i]:Destroy() -- remove is deprecated end end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Change "Hat" to "Accessorie"