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

How to remove all hats except one kind?

Asked by 9 years ago
function onTouched(hit) 
    local d = hit.Parent:GetChildren() 
    for i=1, #d do 
        if (d[i].className == "Hat") and d.Name ~= "Helmet" then 
            d[i]:remove() 
        end 
    end
end 

script.Parent.Touched:connect(onTouched) 

I want this is remove the players hats, EXCEPT for a hat named "Helmet" There is no error in output, it just removes everyones hats. I am trying to make a war game, and I need so when the players 'join' or touch the button they lose their real hats, and are left with a helmet that they are given.

Answer this question