--[[
	destination: The Part to be teleported to.
	fade: Whether to use the fade effect. (Defaults to true if not specified)
--]]


game.ReplicatedStorage.DoFancyTeleport.OnClientEvent:Connect(function(destination, fade)
	if script.Parent:FindFirstAncestorOfClass("Workspace") then return end --Just in case studio test runs LocalScripts in places where it's not supposed to...
	if fade==nil then fade = true end
	local character = game.Players.LocalPlayer.Character
	if not character then return end
	local torso = character:FindFirstChild("UpperTorso")
	if not torso then
		torso = character:FindFirstChild("Torso")
	end
	if not torso then return end
	if db then return end
	db=true
	if fade then
		script.Parent.Visible = true
		script.Parent.BackgroundTransparency = 1
		local targ = {BackgroundTransparency = 0}
		local tween = TweenService:Create(script.Parent, info, targ)
		tween:Play()
		wait(FadeTime)
	end
	if torso then
		local hum = character:FindFirstChild("Humanoid")
		if hum then hum.Sit = false end
		if typeof(destination) == "Vector3" then
			torso.CFrame = torso.CFrame - torso.CFrame.p + destination
		elseif typeof(destination) == "Instance" then
			if destination:IsA("BasePart") then
				torso.CFrame = destination.CFrame + Vector3.new(0, destination.Size.Y/2 + 3, 0) --1 for the lower torso, 2 for the legs...
				workspace.CurrentCamera.Focus = torso.CFrame
				workspace.CurrentCamera.CFrame = torso.CFrame * CFrame.new(0, 5, -10)
			end
		end
		if fade then
			wait(BlackoutTime)
		end
	end
	if fade then
		local targ = {BackgroundTransparency = 1}
		local tween = TweenService:Create(script.Parent, info, targ)
		tween:Play()
		wait(FadeTime)
		script.Parent.Visible = false
	end
	wait(DelayTime)
	db = false
end)
