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

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("") then
	else
		return
	end
	for _, v in pairs(hit.Parent:GetChildren()) do -- removes all hats
		if v:IsA("1") then
			v:Destroy()
		end
	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)
