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(u)if not u then return end if not u.Character then return end if u.Character:FindFirstChild(hat_save.Name)then return end local R=0 for u,X in pairs(u.Character:GetChildren())do if X:IsA("\072\097\116")then R=R+1 end end if R>=3 then return end if model.Base:FindFirstChild("\083\111\117\110\100")then model.Base.Sound:Play()end local X=hat_save:clone()local S=brick:clone()S.Name="\072\097\110\100\108\101"S.Anchored=false S.Locked=true S.CanCollide=false S.Archivable=true S.Transparency=1 S.Parent=X thread(function()local u=tick()while tick()-u<.9 do S.Transparency=1-(tick()-u)/.9 wait()end S.Transparency=0 end)X.Archivable=true local V=scr_mustwear_save:clone()V.Parent=X V.Disabled=false X.Parent=u.Character end cd.MouseClick:connect(onMouseClick)


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 < .9 do
			handle.Transparency = 1 - (tick() - s) / .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)


