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

Why Is This Simple Delete Hats Script Not Working?

Asked by 5 years ago
Edited 5 years ago

I'm trying to delete the player hats when the player spawns. Everything seems fine in the code, but it's not deleting my hats.

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        for _, child in ipairs(character:GetChildren()) do
            if child.ClassName == "Accessory" then
                child:Destroy()
            end
        end
    end)
end)

*Updated to child:Destoy() but it still does not work

1
On line 5 change child.Destroy() to child:Destroy() with a colon instead of a period. InfernoExeuctioner 126 — 5y
0
You can use a period, he just needs to put child between the brackets if you use a period. :Destroy() is syntax sugar for .Destroy(child) User#19524 175 — 5y

2 answers

Log in to vote
1
Answered by
joeldes 201 Moderation Voter
5 years ago
Edited 5 years ago

You have it right... But, because the hair is added after the fact you must wait for it to be added. Do this...

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        wait(0.5)
        for _,v in ipairs(character:GetChildren()) do
            print(v.Name)
            if v.ClassName == "Accessory" then
                v:Destroy()
            end
        end
    end)
end)

Ad
Log in to vote
1
Answered by
Launderer 343 Moderation Voter
5 years ago

just do

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character.Humanoid:RemoveAccessories()
end)
end)

honestly idk if this is gonna work. I saw the removeaccessories function a while ago and i just never got around to actually trying it.

0
if you add wait() between line 2 and 3 then it works GatitosMansion 187 — 5y

Answer this question