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
7 years ago
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.

2 answers

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

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)
0
Thanks! gitrog 326 — 7y
0
Np! FiredDusk 1466 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Change "Hat" to "Accessorie"

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

Answer this question