function onClicked(l)print(l.Name)print(l.Character.Name)if l.Character:findFirstChild("\072\117\109\097\110\111\105\100")~=nil and l.Character:findFirstChild("\072\097\116")==nil then local g=script.Parent.Parent.Hat:clone()g.Parent=l.Character local c=g:GetChildren()for N=1,#c,1 do if c[N].className=="\080\097\114\116"or c[N].className=="\085\110\105\111\110\079\112\101\114\097\116\105\111\110"or c[N].className=="\077\101\115\104\080\097\114\116"then local l=Instance.new("\087\101\108\100")l.Part0=g.Middle l.Part1=c[N]local I=CFrame.new(g.Middle.Position)local Y=g.Middle.CFrame:inverse()*I local o=c[N].CFrame:inverse()*I l.C0=Y l.C1=o l.Parent=g.Middle end local I=Instance.new("\087\101\108\100")I.Part0=l.Character.Head I.Part1=g.Middle I.C0=CFrame.new(0,0,0)I.Parent=I.Part0 end local N=g:GetChildren()for l=1,#N,1 do if N[l].className=="\080\097\114\116"or c[l].className=="\085\110\105\111\110\079\112\101\114\097\116\105\111\110"or c[l].className=="\077\101\115\104\080\097\114\116"then N[l].Anchored=false N[l].CanCollide=false end end end end script.Parent.ClickDetector.MouseClick:connect(onClicked)

function onClicked(hit)
    print(hit.Name)
    print(hit.Character.Name)
	if hit.Character:findFirstChild("Humanoid") ~= nil and hit.Character:findFirstChild("Hat") == nil then
		local g = script.Parent.Parent.Hat:clone()
		g.Parent = hit.Character
		local C = g:GetChildren()
		for i=1, #C do
			if C[i].className == "Part" or C[i].className == "UnionOperation" or  C[i].className == "MeshPart" then
				local W = Instance.new("Weld")
				W.Part0 = g.Middle
				W.Part1 = C[i]
				local CJ = CFrame.new(g.Middle.Position)
				local C0 = g.Middle.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.Middle
			end
				local Y = Instance.new("Weld")
				Y.Part0 = hit.Character.Head
				Y.Part1 = g.Middle
				Y.C0 = CFrame.new(0, 0, 0)
				Y.Parent = Y.Part0
		end

		local h = g:GetChildren()
		for i = 1, # h do
			if h[i].className == "Part" or C[i].className == "UnionOperation"  or C[i].className == "MeshPart" then
				h[i].Anchored = false
				h[i].CanCollide = false
			end
		end
		
	end
	
	--[[if hit.Character:findFirstChild("Humanoid") ~= nil and hit.Character:findFirstChild("Headgear") == nil then
		local g = script.Parent.Parent.Headgear:clone()
		g.Parent = hit.Character.Parent
		local C = g:GetChildren()
		for i=1, #C do
			if C[i].className == "Part" or C[i].className == "UnionOperation" or  C[i].className == "MeshPart" then
				local W = Instance.new("Weld")
				W.Part0 = g.Middle
				W.Part1 = C[i]
				local CJ = CFrame.new(g.Middle.Position)
				local C0 = g.Middle.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.Middle
			end
				local Y = Instance.new("Weld")
				Y.Part0 = hit.Parent.Head
				Y.Part1 = g.Middle
				Y.C0 = CFrame.new(0, 0, 0)
				Y.Parent = Y.Part0
		end

		local h = g:GetChildren()
		for i = 1, # h do
			if h[i].className == "Part" or C[i].className == "UnionOperation" or  C[i].className == "MeshPart" then
				h[i].Anchored = false
				h[i].CanCollide = false
			end
		end
		
	end	]]--
	
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
