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

Remove default hat(s) on join?

Asked by 7 years ago
Edited 7 years ago

I've tried to everything to find one working script (because mine didn't work at all). Apparently, they all don't work. Can anyone help me?

while true do 
wait(0.1) 
local w = game.Workspace:GetChildren() 
for i = 1, #w do 
c = w[i]:GetChildren()
for i=1, #c do
if (c[i].className == "Hat") then 
c[i]:remove() 
end
end 
end 
end 

1
Scripting Helpers is not a request site; please edit your post to include your code. Pyrondon 2089 — 7y
0
The ClassName is "Accessory" User#13357 0 — 7y

3 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
--ClassNames or Names
local banned = {

    Hat = true, 
    Accoutrement = true,
    Accessory = true;

}


function delete(obj)
    if banned[obj.ClassName] or banned[obj.Name] then
        game.Debris:AddItem(obj, 1/30)
        print("Deleted: " ..obj.Name)
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(c)
        c.DescendantAdded:connect(function(obj)
            delete(obj)
        end)
    end)
end)


Ad
Log in to vote
0
Answered by
Zeoic 40
7 years ago

They are no longer considered "Hat" they are now "Accessory".

Log in to vote
0
Answered by 7 years ago

Though both of them are valid-ish answers. Simplicity calls for an even better one!

-- || Services || -- 
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")

-- || HatRemoval || --
Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        for i,v in pairs(Character:GetChildren()) do
            if v:IsA("Accoutrement") then
                Debris:AddItem(v, 1)
                    end end 
        Character.ChildAdded:connect(function(Item)
            if Item:IsA("Accoutrement") then
                Debris(Item, 1)
                    end
end) end) end)


-- Note: You don't have to use Debris, I just use it because I like it so it doesn't pause code to :Destroy() something.

So yeah, as you can see, there's many ways to do this, though my way is a way I've used a lot as someone that makes these scripts (sadly) a lot.

Any questions? Be sure to ask any of us!

Answer this question