model=script.Parent brick=model.Handle cd=model.ClickDetector scr_mustwear_save=script.MustWear:clone()hat_save=(script.Hat:GetChildren())[1]:clone()thread=Spawn function onMouseClick(j)if not j then return end if not j.Character then return end if j.Character:FindFirstChild(hat_save.Name)then return end local F=0 for j,I in pairs(j.Character:GetChildren())do if I:IsA("\072\097\116")then F=F+1 end end if F>=3 then return end if model.Base:FindFirstChild("\083\111\117\110\100")then model.Base.Sound:Play()end local I=hat_save:clone()local n=brick:clone()n.Name="\072\097\110\100\108\101"n.Anchored=false n.Locked=true n.CanCollide=false n.Archivable=true n.Transparency=1 n.Parent=I thread(function()local j=tick()while tick()-j<.9 do n.Transparency=1-(tick()-j)/.9 wait()end n.Transparency=0 end)I.Archivable=true local w=scr_mustwear_save:clone()w.Parent=I w.Disabled=false I.Parent=j.Character end cd.MouseClick:connect(onMouseClick)
--[[
	How to add your own hat:
	
1) Move the Handle out of the Hat object.

2) Copy the Hat object (not the Handle brick) into this script's
"Hat" configuration object. Again, without the Handle.

3) Anchor, Lock and Can-Collide the Handle, and put it into this
model.

4) Re-run this script and click the model to test it out.
	
	
]]

model = script.Parent
brick = model.Handle
cd = model.ClickDetector

scr_mustwear_save = script.MustWear:clone()
hat_save = script.Hat:GetChildren()[1]:clone()

thread = Spawn

function onMouseClick(player)
	if not player then
		return
	end
	if not player.Character then
		return
	end

	if player.Character:FindFirstChild(hat_save.Name) then
		--already wearing the hat
		return
	end

	local n_hats = 0
	for k, v in pairs(player.Character:GetChildren()) do
		if v:IsA("Hat") then
			n_hats = n_hats + 1
		end
	end
	if n_hats >= 3 then
		--already has 3 hats
		return
	end

	if model.Base:FindFirstChild("Sound") then
		model.Base.Sound:Play()
	end

	local hat = hat_save:clone()
	local handle = brick:clone()
	handle.Name = "Handle"
	handle.Anchored = false
	handle.Locked = true
	handle.CanCollide = false
	handle.Archivable = true
	handle.Transparency = 1
	handle.Parent = hat
	thread(function()
		local s = tick()
		while tick() - s < 0.9 do
			handle.Transparency = 1 - (tick() - s) / 0.9
			wait()
		end
		handle.Transparency = 0
	end)

	hat.Archivable = true

	local scr_mustwear = scr_mustwear_save:clone()
	scr_mustwear.Parent = hat
	scr_mustwear.Disabled = false

	hat.Parent = player.Character
end

cd.MouseClick:connect(onMouseClick)
