local g=script.Parent g.PrimaryPart=g:WaitForChild("\072\101\097\100")function weldParts(g,S)local K=Instance.new("\087\101\108\100")K.Part0=g K.Part1=S K.C0=CFrame.new()K.C1=S.CFrame:toObjectSpace(g.CFrame)K.Parent=g end g.Head.Touched:connect(function(S)if S.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")and not S.Parent:FindFirstChild("\069\097\114\108\'\115 \067\111\114\111\110\101\116")then else return end local K=S.Parent:FindFirstChild("\072\101\097\100")local o=g:Clone();(o:FindFirstChild("\072\097\116\083\099\114\105\112\116")):Destroy()o:SetPrimaryPartCFrame(K.CFrame)o.PrimaryPart:Destroy()for g,S in pairs(o:GetChildren())do if S:IsA("\066\097\115\101\080\097\114\116")then weldParts(K,S)S.CanCollide=false S.Anchored=false end end o.Parent=S.Parent end)


local hat = script.Parent
hat.PrimaryPart = hat:WaitForChild("Head") -- Make sure the Head is the same size as a normal Head.

function weldParts(part0, part1) -- welds the 2 parts based on their position
	local newWeld = Instance.new("Weld")
	newWeld.Part0  = part0
	newWeld.Part1  = part1
	newWeld.C0     = CFrame.new()
	newWeld.C1     = part1.CFrame:toObjectSpace(part0.CFrame)
	newWeld.Parent = part0
end

hat.Head.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid")  and not hit.Parent:FindFirstChild("Earl's Coronet")then else return end

	local head = hit.Parent:FindFirstChild("Head")
	local newHat = hat:Clone()
	newHat:FindFirstChild("HatScript"):Destroy()
	newHat:SetPrimaryPartCFrame(head.CFrame) -- puts the head into the head
	newHat.PrimaryPart:Destroy()
	for _, part in pairs (newHat:GetChildren()) do
		if part:IsA("BasePart") then
			weldParts(head, part)
			part.CanCollide = false
			part.Anchored = false
		end
	end
	newHat.Parent = hit.Parent
end)
