I'm trying to make a thing where if you click this button, a union is added to your body (your head more specifically) and it just teleports me to where I built the unions. What do I do? The part 1 and part 0 switching doesn't work.

local replicatedstorage = game:GetService("ReplicatedStorage")


local currentanim = script.PacManAnims.CurrentAnim
local equipped = {}



local looping = true

local function Animate(animations, item, player)
	local animnumber = 1
	
	replicatedstorage:WaitForChild("EndGame").OnServerEvent:Connect(function()
		while animnumber == not 1 do
			animnumber = animnumber - 1
			wait(0.1)
		end
	end)
	
	while looping == true do 
		if animnumber == #animations then
			animnumber = 1
		else
			animnumber = animnumber + 1
		end
		
		local anim = animations[animnumber]
		
		for i,v in pairs(animations) do
			if v == anim then
				v.Parent = workspace[player.Name]
				
				local MotorSixD = Instance.new("Motor6D")
				MotorSixD.Name = "Motor6D"
				MotorSixD.Parent = v
				MotorSixD.Part0 = workspace[player.Name].Head
				MotorSixD.Part1 = v
			else
				if v:FindFirstChild("Motor6D") then
					v:FindFirstChild("Motor6D"):Destroy()
				end
				v.Parent = item
			end
		end
		wait(0.1)
	end
end

replicatedstorage:WaitForChild("EquippedItem").OnServerEvent:Connect(function(player, equippeditem)
	local item = script.PacManAnims:FindFirstChild(equippeditem)
	local children = item:GetChildren()
	children.Parent = currentanim
	equipped = item.Name
	Animate(children, item, player)
end)