01 | function onClicked(playerWhoClicked) |
02 | local playerBody = game.Workspace [ playerWhoClicked.Name ] |
03 | local d = playerBody.Parent:GetChildren() |
04 | for i = 1 , #d do |
05 | if (d [ i ] .className = = "Hat" ) then |
06 | d [ i ] :remove() |
07 | end |
08 | end |
09 | end |
10 |
11 | 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.
01 | function onClicked(playerWhoClicked) |
02 | local playerBody = game.Workspace [ playerWhoClicked.Name ] -- or you could just do "playerWhoClicked.Character" |
03 | local d = playerBody:GetChildren() -- You don't need to get the parent, you already have the character. |
04 | for i = 1 , #d do |
05 | if (d [ i ] :IsA( "Hat" ) or d [ i ] :IsA( "Accessory" )) then -- "ClassName" is deprecated. You should also find a Accessory. |
06 | d [ i ] :Destroy() -- remove is deprecated |
07 | end |
08 | end |
09 | end |
10 |
11 | script.Parent.ClickDetector.MouseClick:connect(onClicked) |
Change "Hat" to "Accessorie"