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:

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

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

local children = Part.Parent:GetChildren()
for _, child in ipairs(children) do
    --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 5 years ago
script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        for i, v in pairs(hit.Parent:GetChildren()) do
            if v:IsA("Accessory") or v:IsA("Hat") then
                v:Destroy()
            end
        end
    end
end)
Ad

Answer this question