Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Hat remover not removing hats, no errors?

Asked by
gitrog 326 Moderation Voter
8 years ago
01function 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
09end
10 
11script.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.

2 answers

Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
8 years ago

if this helped, please be sure to accept my answer :) I have left some comments below.

01function 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
09end
10 
11script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Thanks! gitrog 326 — 8y
0
Np! FiredDusk 1466 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Change "Hat" to "Accessorie"

0
*Accessory* IfIWasntSoSwag 98 — 8y
0
Still nothing. gitrog 326 — 8y

Answer this question