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!
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)