--Connect our event. The function wants to know the start and end teleporter, and the part that triggered the teleport.

networking.StartEffect.OnClientEvent:connect(function(part,tele1,tele2)
	local parts = {}
	getAssemblyParts(part,parts) --Get the entire assembly
	
	local soundPart1 = tele1:clone()
	soundPart1.Transparency = 1
	soundPart1.Parent = camera
	
	local soundPart2 = tele2:clone()
	soundPart2.Transparency = 1
	soundPart2.Parent = camera
	
	soundPart1.Teleport:play()
	soundPart2.Teleport:play()
	
	local effect1 = {}
	local effect2 = {}
	
	for _,pt in pairs(parts) do
		local part = pt:clone()
		part.Anchored = true
		part.CanCollide = false
		part.Transparency = 1
		part.Material = Enum.Material.Neon
		pcall(function() part.FormFactor = Enum.FormFactor.Custom end)
		part.Size = part.Size * 1.1
		part.Parent = camera
		effect1[part] = pt.CFrame
		
		local part = pt:clone()
		part.Anchored = true
		part.CanCollide = false
		part.Transparency = 1
		part.Material = Enum.Material.Neon
		pcall(function() part.FormFactor = Enum.FormFactor.Custom end)
		part.Size = part.Size * 1.1
		part.Parent = camera
		effect2[part] = tele2.CFrame * tele1.CFrame:toObjectSpace(pt.CFrame)
	end
	
	local start = tick()
	while tick() < start+4 do
		wait()
		local t = tick()-start
		local x = t*(2.31/4)
		
		local trans = -0.7*x^3 + 2.6*x^2 - 2.7*x + 1
		tele1.Parent.Glow.Transparency = 1 - math.pow((x - 2.25) / 2.25,2)
		tele2.Parent.Glow.Transparency = 1 - math.pow((x - 2.25) / 2.25,2)
		
		for k,v in pairs(effect1) do
			k.CFrame = v
			k.Transparency = trans
		end
		for k,v in pairs(effect2) do
			k.CFrame = v
			k.Transparency = trans
		end
	end
	local tele1color = tele1.Parent.Glow.BrickColor
	local tele2color = tele2.Parent.Glow.BrickColor
	
	tele1.Parent.Glow.BrickColor = BrickColor.new("Pastel light blue")
	tele2.Parent.Glow.BrickColor = BrickColor.new("Pastel light blue")
	
	wait(0.05)
	
	tele1.Parent.Glow.BrickColor = tele1color
	tele2.Parent.Glow.BrickColor = tele2color
	
	wait(0.45)
	
	local start = tick()
	while tick() < start+1 do
		wait()
		local t = tick()-start
		local trans = t
		
		tele1.Parent.Glow.Transparency = 1-t
		
		for k,v in pairs(effect1) do
			k.Size = k.Size * 1.01
			k.CFrame = v
			k.Transparency = trans
		end
		for k,v in pairs(effect2) do
			k.Size = k.Size * 1.01
			k.CFrame = v
			k.Transparency = trans
		end
	end
	
	for k,v in pairs(effect1) do k:Destroy() end
	for k,v in pairs(effect2) do k:Destroy() end
	
	tele1.Parent.Glow.Transparency = 0
	
	soundPart1:Destroy()
	soundPart2:Destroy()
end)
