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

How do I remove hats onjoin?

Asked by 9 years ago

I tried findfirstchild waitforchild its so annoying please help I want the players hat to be destroyed when they join.

1 answer

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
9 years ago

If you want all the hats a player has to be destroyed everytime they respawn, then instead of using waitforchild or findfirstchild, you should use the PlayerAdded event and CharacterAdded event to search through the entire character for hats using the :IsA() method and then destroy the hat.

local players = game:GetService'Players' -- Get the players service

players.PlayerAdded:connect(function(p)
    p.CharacterAdded:connect(function(c) --This event will fire whenever the character is spawned
        wait(.8) -- Hats take a few second to load
        for i,v in next,c:GetChildren() do --Search through the entire character
            if v:IsA("Hat") then -- Check if v is a hat
                v:Destroy() --Destroy the hat
            end
        end
    end)
end)




0
Your normal version of this script didn't work I tried making it a script and a localscript. Clakker200 5 — 9y
0
Try it again with the wait, I forgot that hats take a little time to be loaded in by the game server. 4Bros 550 — 9y
0
k thanks Clakker200 5 — 9y
0
I added a wait for 10 I even made them localscripts and scripts into workspace and starterpack any idea why it doesnt work? Clakker200 5 — 9y
Ad

Answer this question