Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I remove hats onjoin?

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

1 answer

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)




4 comments

0

Your normal version of this script didn't work I tried making it a script and a localscript.

0

Try it again with the wait, I forgot that hats take a little time to be loaded in by the game server.

0

k thanks

0

I added a wait for 10 I even made them localscripts and scripts into workspace and starterpack any idea why it doesnt work?

This discussion is preserved as it was. New answers, comments, and votes are closed.