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

How to :Destroy() hats in Player?

Asked by 8 years ago

I've been wondering how to get rid of all the hats that are descendants of a player that touches a brick. Here's an example block of code that is inside the brick:

1local function changePlayer(Part)
2    if hum = Part.Parent:FindFirstChild("Humanoid") then
3    --A block of code that removes all hats--
4    end
5end
6script.Parent.Touched:connect(changePlayer)

In the "--A block of code that removes all hats--" part, I was thinking of doing this

1local children = Part.Parent:GetChildren()
2for _, child in ipairs(children) do
3    --Block of Code that Removes Hats--

Will this work? I'm really struggling for a simple way to do this. Thanks!

1 answer

Log in to vote
0
Answered by 6 years ago
1script.Parent.Touched:connect(function(hit)
2    if hit.Parent:FindFirstChild("Humanoid") then
3        for i, v in pairs(hit.Parent:GetChildren()) do
4            if v:IsA("Accessory") or v:IsA("Hat") then
5                v:Destroy()
6            end
7        end
8    end
9end)
Ad

Answer this question